[alsa-devel] [RFC 00/16] ASoC: multi-component - CODECs
This is the second part of the multi-component series and focuses on the changes required to support ASoC multi-component on CODEC drivers.
I've split the CODEC driver patches into smaller chunks and tried to group (where possible) similar CODECs together. All the patches will be rebased together at upstream time so we don't break bisect.
Most CODEC drivers were extremely straight forward with changes limited to their probe() and remove() sections. Some CODECs did require a little extra work and this is marked in their commit messages.
Thanks
Liam
Move AKM CODECs to multi-component model.
This patch changes the probe() and remove() of the CODEC drivers as follows:-
o Make CODEC driver a platform device (non MFD codecs only) o Moved all struct snd_soc_codec list, mutex, etc initialiasation to core. o Removed all static codec pointers (drivers now support > 1 codec dev) o snd_soc_register_pcms() now done by core. o snd_soc_register_dai() folded into snd_soc_register_codec(). o codec cache can now be malloc()ed by core.
Other required changes due to multi-component model :-
o ak4535: set_bias_level() has to perform mute IO directly rather than via ak4535 mute since struct codec no longer contains dai.
Signed-off-by: Liam Girdwood lrg@slimlogic.co.uk --- sound/soc/codecs/ak4104.c | 146 +++++++++++------------------ sound/soc/codecs/ak4104.h | 4 +- sound/soc/codecs/ak4535.c | 234 ++++++++++++--------------------------------- sound/soc/codecs/ak4535.h | 9 +-- sound/soc/codecs/ak4642.c | 166 +++++++------------------------ sound/soc/codecs/ak4642.h | 4 +- sound/soc/codecs/ak4671.c | 137 ++++++--------------------- sound/soc/codecs/ak4671.h | 4 +- 8 files changed, 192 insertions(+), 512 deletions(-)
diff --git a/sound/soc/codecs/ak4104.c b/sound/soc/codecs/ak4104.c index 192aebd..890122d 100644 --- a/sound/soc/codecs/ak4104.c +++ b/sound/soc/codecs/ak4104.c @@ -48,8 +48,8 @@ #define DRV_NAME "ak4104"
struct ak4104_private { - struct snd_soc_codec codec; - u8 reg_cache[AK4104_NUM_REGS]; + enum snd_soc_control_type control_type; + void *control_data; };
static int ak4104_fill_cache(struct snd_soc_codec *codec) @@ -58,7 +58,7 @@ static int ak4104_fill_cache(struct snd_soc_codec *codec) u8 *reg_cache = codec->reg_cache; struct spi_device *spi = codec->control_data;
- for (i = 0; i < codec->reg_cache_size; i++) { + for (i = 0; i < codec->driver->reg_cache_size; i++) { int ret = spi_w8r8(spi, i | AK4104_READ); if (ret < 0) { dev_err(&spi->dev, "SPI write failure\n"); @@ -76,7 +76,7 @@ static unsigned int ak4104_read_reg_cache(struct snd_soc_codec *codec, { u8 *reg_cache = codec->reg_cache;
- if (reg >= codec->reg_cache_size) + if (reg >= codec->driver->reg_cache_size) return -EINVAL;
return reg_cache[reg]; @@ -88,7 +88,7 @@ static int ak4104_spi_write(struct snd_soc_codec *codec, unsigned int reg, u8 *cache = codec->reg_cache; struct spi_device *spi = codec->control_data;
- if (reg >= codec->reg_cache_size) + if (reg >= codec->driver->reg_cache_size) return -EINVAL;
/* only write to the hardware if value has changed */ @@ -145,8 +145,7 @@ static int ak4104_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; int val = 0;
/* set the IEC958 bits: consumer mode, no copyright bit */ @@ -178,7 +177,7 @@ static struct snd_soc_dai_ops ak4101_dai_ops = { .set_fmt = ak4104_set_dai_fmt, };
-struct snd_soc_dai ak4104_dai = { +struct snd_soc_dai_driver ak4104_dai = { .name = DRV_NAME, .playback = { .stream_name = "Playback", @@ -192,45 +191,17 @@ struct snd_soc_dai ak4104_dai = { .ops = &ak4101_dai_ops, };
-static struct snd_soc_codec *ak4104_codec; - -static int ak4104_spi_probe(struct spi_device *spi) +static int ak4104_probe(struct snd_soc_codec *codec) { - struct snd_soc_codec *codec; - struct ak4104_private *ak4104; + struct ak4104_private *ak4104 = snd_soc_codec_get_drvdata(codec); int ret, val;
- spi->bits_per_word = 8; - spi->mode = SPI_MODE_0; - ret = spi_setup(spi); - if (ret < 0) - return ret; - - ak4104 = kzalloc(sizeof(struct ak4104_private), GFP_KERNEL); - if (!ak4104) { - dev_err(&spi->dev, "could not allocate codec\n"); - return -ENOMEM; - } - - codec = &ak4104->codec; - mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - codec->dev = &spi->dev; - codec->name = DRV_NAME; - codec->owner = THIS_MODULE; - codec->dai = &ak4104_dai; - codec->num_dai = 1; - snd_soc_codec_set_drvdata(codec, ak4104); - codec->control_data = spi; - codec->reg_cache = ak4104->reg_cache; - codec->reg_cache_size = AK4104_NUM_REGS; + codec->control_data = ak4104->control_data;
/* read all regs and fill the cache */ ret = ak4104_fill_cache(codec); if (ret < 0) { - dev_err(&spi->dev, "failed to fill register cache\n"); + dev_err(codec->dev, "failed to fill register cache\n"); return ret; }
@@ -238,93 +209,84 @@ static int ak4104_spi_probe(struct spi_device *spi) * should contain 0x5b. Not a good way to verify the presence of * the device, but there is no hardware ID register. */ if (ak4104_read_reg_cache(codec, AK4104_REG_RESERVED) != - AK4104_RESERVED_VAL) { - ret = -ENODEV; - goto error_free_codec; - } + AK4104_RESERVED_VAL) + return -ENODEV;
/* set power-up and non-reset bits */ val = ak4104_read_reg_cache(codec, AK4104_REG_CONTROL1); val |= AK4104_CONTROL1_PW | AK4104_CONTROL1_RSTN; ret = ak4104_spi_write(codec, AK4104_REG_CONTROL1, val); if (ret < 0) - goto error_free_codec; + return ret;
/* enable transmitter */ val = ak4104_read_reg_cache(codec, AK4104_REG_TX); val |= AK4104_TX_TXE; ret = ak4104_spi_write(codec, AK4104_REG_TX, val); if (ret < 0) - goto error_free_codec; - - ak4104_codec = codec; - ret = snd_soc_register_dai(&ak4104_dai); - if (ret < 0) { - dev_err(&spi->dev, "failed to register DAI\n"); - goto error_free_codec; - } + return ret;
- spi_set_drvdata(spi, ak4104); - dev_info(&spi->dev, "SPI device initialized\n"); + dev_info(codec->dev, "SPI device initialized\n"); return 0; - -error_free_codec: - kfree(ak4104); - ak4104_dai.dev = NULL; - return ret; }
-static int __devexit ak4104_spi_remove(struct spi_device *spi) +static int ak4104_remove(struct snd_soc_codec *codec) { - int ret, val; - struct ak4104_private *ak4104 = spi_get_drvdata(spi); + int val, ret;
- val = ak4104_read_reg_cache(&ak4104->codec, AK4104_REG_CONTROL1); + val = ak4104_read_reg_cache(codec, AK4104_REG_CONTROL1); if (val < 0) return val;
/* clear power-up and non-reset bits */ val &= ~(AK4104_CONTROL1_PW | AK4104_CONTROL1_RSTN); - ret = ak4104_spi_write(&ak4104->codec, AK4104_REG_CONTROL1, val); - if (ret < 0) - return ret; + ret = ak4104_spi_write(codec, AK4104_REG_CONTROL1, val);
- ak4104_codec = NULL; - kfree(ak4104); - return 0; + return ret; }
-static int ak4104_probe(struct platform_device *pdev) +struct snd_soc_codec_driver soc_codec_device_ak4104 = { + .name = DRV_NAME, + .owner = THIS_MODULE, + .probe = ak4104_probe, + .remove = ak4104_remove, + .reg_cache_size = AK4104_NUM_REGS, + .reg_word_size = sizeof(u16), +}; +EXPORT_SYMBOL_GPL(soc_codec_device_ak4104); + +static int ak4104_spi_probe(struct spi_device *spi) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = ak4104_codec; + struct ak4104_private *ak4104; int ret;
- /* Connect the codec to the socdev. snd_soc_new_pcms() needs this. */ - socdev->card->codec = 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\n"); + spi->bits_per_word = 8; + spi->mode = SPI_MODE_0; + ret = spi_setup(spi); + if (ret < 0) return ret; - }
- return 0; + ak4104 = kzalloc(sizeof(struct ak4104_private), GFP_KERNEL); + if (ak4104 == NULL) + return -ENOMEM; + + ak4104->control_data = spi; + ak4104->control_type = SND_SOC_SPI; + spi_set_drvdata(spi, ak4104); + + ret = snd_soc_register_codec(&spi->dev, spi->chip_select, + &soc_codec_device_ak4104, &ak4104_dai, 1); + if (ret < 0) + kfree(ak4104); + return ret; }
-static int ak4104_remove(struct platform_device *pdev) +static int __devexit ak4104_spi_remove(struct spi_device *spi) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - snd_soc_free_pcms(socdev); + snd_soc_unregister_codec(&spi->dev, spi->chip_select); + kfree(spi_get_drvdata(spi)); return 0; -}; - -struct snd_soc_codec_device soc_codec_device_ak4104 = { - .probe = ak4104_probe, - .remove = ak4104_remove -}; -EXPORT_SYMBOL_GPL(soc_codec_device_ak4104); +}
static struct spi_driver ak4104_spi_driver = { .driver = { diff --git a/sound/soc/codecs/ak4104.h b/sound/soc/codecs/ak4104.h index eb88fe7..51e8922 100644 --- a/sound/soc/codecs/ak4104.h +++ b/sound/soc/codecs/ak4104.h @@ -1,7 +1,7 @@ #ifndef _AK4104_H #define _AK4104_H
-extern struct snd_soc_dai ak4104_dai; -extern struct snd_soc_codec_device soc_codec_device_ak4104; +extern struct snd_soc_dai_driver ak4104_dai; +extern struct snd_soc_codec_driver soc_codec_device_ak4104;
#endif diff --git a/sound/soc/codecs/ak4535.c b/sound/soc/codecs/ak4535.c index d425367..a4b3d39 100644 --- a/sound/soc/codecs/ak4535.c +++ b/sound/soc/codecs/ak4535.c @@ -31,11 +31,11 @@
#define AK4535_VERSION "0.3"
-struct snd_soc_codec_device soc_codec_dev_ak4535; - /* codec private data */ struct ak4535_priv { unsigned int sysclk; + enum snd_soc_control_type control_type; + void *control_data; };
/* @@ -313,8 +313,7 @@ static int ak4535_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 ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec); u8 mode2 = ak4535_read_reg_cache(codec, AK4535_MODE2) & ~(0x3 << 5); int rate = params_rate(params), fs = 256; @@ -378,14 +377,16 @@ static int ak4535_mute(struct snd_soc_dai *dai, int mute) static int ak4535_set_bias_level(struct snd_soc_codec *codec, enum snd_soc_bias_level level) { - u16 i; + u16 i, mute_reg;
switch (level) { case SND_SOC_BIAS_ON: - ak4535_mute(codec->dai, 0); + mute_reg = ak4535_read_reg_cache(codec, AK4535_DAC) & 0xffdf; + ak4535_write(codec, AK4535_DAC, mute_reg); break; case SND_SOC_BIAS_PREPARE: - ak4535_mute(codec->dai, 1); + mute_reg = ak4535_read_reg_cache(codec, AK4535_DAC) & 0xffdf; + ak4535_write(codec, AK4535_DAC, mute_reg | 0x20); break; case SND_SOC_BIAS_STANDBY: i = ak4535_read_reg_cache(codec, AK4535_PM1); @@ -413,7 +414,7 @@ static struct snd_soc_dai_ops ak4535_dai_ops = { .set_sysclk = ak4535_set_dai_sysclk, };
-struct snd_soc_dai ak4535_dai = { +struct snd_soc_dai_driver ak4535_dai = { .name = "AK4535", .playback = { .stream_name = "Playback", @@ -431,52 +432,26 @@ struct snd_soc_dai ak4535_dai = { }; EXPORT_SYMBOL_GPL(ak4535_dai);
-static int ak4535_suspend(struct platform_device *pdev, pm_message_t state) +static int ak4535_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; - ak4535_set_bias_level(codec, SND_SOC_BIAS_OFF); return 0; }
-static int ak4535_resume(struct platform_device *pdev) +static int ak4535_resume(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; ak4535_sync(codec); ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY); return 0; }
-/* - * initialise the AK4535 driver - * register the mixer and dsp interfaces with the kernel - */ -static int ak4535_init(struct snd_soc_device *socdev) +static int ak4535_probe(struct snd_soc_codec *codec) { - struct snd_soc_codec *codec = socdev->card->codec; - int ret = 0; + struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec);
- codec->name = "AK4535"; - codec->owner = THIS_MODULE; - codec->read = ak4535_read_reg_cache; - codec->write = ak4535_write; - codec->set_bias_level = ak4535_set_bias_level; - codec->dai = &ak4535_dai; - codec->num_dai = 1; - codec->reg_cache_size = ARRAY_SIZE(ak4535_reg); - codec->reg_cache = kmemdup(ak4535_reg, sizeof(ak4535_reg), GFP_KERNEL); - - if (codec->reg_cache == NULL) - return -ENOMEM; + printk(KERN_INFO "AK4535 Audio Codec %s", AK4535_VERSION);
- /* register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret < 0) { - printk(KERN_ERR "ak4535: failed to create pcms\n"); - goto pcm_err; - } + codec->control_data = ak4535->control_data;
/* power on device */ ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY); @@ -485,39 +460,58 @@ static int ak4535_init(struct snd_soc_device *socdev) ARRAY_SIZE(ak4535_snd_controls)); ak4535_add_widgets(codec);
- return ret; - -pcm_err: - kfree(codec->reg_cache); + return 0; +}
- return ret; +/* power down chip */ +static int ak4535_remove(struct snd_soc_codec *codec) +{ + ak4535_set_bias_level(codec, SND_SOC_BIAS_OFF); + return 0; }
-static struct snd_soc_device *ak4535_socdev; +struct snd_soc_codec_driver soc_codec_dev_ak4535 = { + .name = "AK4535", + .owner = THIS_MODULE, + .probe = ak4535_probe, + .remove = ak4535_remove, + .suspend = ak4535_suspend, + .resume = ak4535_resume, + .read = ak4535_read_reg_cache, + .write = ak4535_write, + .set_bias_level = ak4535_set_bias_level, + .reg_cache_size = ARRAY_SIZE(ak4535_reg), + .reg_word_size = sizeof(u8), + .reg_cache_default = ak4535_reg, +}; +EXPORT_SYMBOL_GPL(soc_codec_dev_ak4535);
#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) - -static int ak4535_i2c_probe(struct i2c_client *i2c, - const struct i2c_device_id *id) +static __devinit int ak4535_i2c_probe(struct i2c_client *i2c, + const struct i2c_device_id *id) { - struct snd_soc_device *socdev = ak4535_socdev; - struct snd_soc_codec *codec = socdev->card->codec; + struct ak4535_priv *ak4535; int ret;
- i2c_set_clientdata(i2c, codec); - codec->control_data = i2c; + ak4535 = kzalloc(sizeof(struct ak4535_priv), GFP_KERNEL); + if (ak4535 == NULL) + return -ENOMEM; + + i2c_set_clientdata(i2c, ak4535); + ak4535->control_data = i2c; + ak4535->control_type = SND_SOC_I2C;
- ret = ak4535_init(socdev); + ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &soc_codec_dev_ak4535, &ak4535_dai, 1); if (ret < 0) - printk(KERN_ERR "failed to initialise AK4535\n"); - + kfree(ak4535); return ret; }
-static int ak4535_i2c_remove(struct i2c_client *client) +static __devexit int ak4535_i2c_remove(struct i2c_client *client) { - struct snd_soc_codec *codec = i2c_get_clientdata(client); - kfree(codec->reg_cache); + snd_soc_unregister_codec(&client->dev, client->addr); + kfree(i2c_get_clientdata(client)); return 0; }
@@ -533,134 +527,30 @@ static struct i2c_driver ak4535_i2c_driver = { .owner = THIS_MODULE, }, .probe = ak4535_i2c_probe, - .remove = ak4535_i2c_remove, + .remove = __devexit_p(ak4535_i2c_remove), .id_table = ak4535_i2c_id, }; - -static int ak4535_add_i2c_device(struct platform_device *pdev, - const struct ak4535_setup_data *setup) -{ - struct i2c_board_info info; - struct i2c_adapter *adapter; - struct i2c_client *client; - int ret; - - ret = i2c_add_driver(&ak4535_i2c_driver); - if (ret != 0) { - dev_err(&pdev->dev, "can't add i2c driver\n"); - return ret; - } - - memset(&info, 0, sizeof(struct i2c_board_info)); - info.addr = setup->i2c_address; - strlcpy(info.type, "ak4535", I2C_NAME_SIZE); - - adapter = i2c_get_adapter(setup->i2c_bus); - if (!adapter) { - dev_err(&pdev->dev, "can't get i2c adapter %d\n", - setup->i2c_bus); - goto err_driver; - } - - client = i2c_new_device(adapter, &info); - i2c_put_adapter(adapter); - if (!client) { - dev_err(&pdev->dev, "can't add i2c device at 0x%x\n", - (unsigned int)info.addr); - goto err_driver; - } - - return 0; - -err_driver: - i2c_del_driver(&ak4535_i2c_driver); - return -ENODEV; -} #endif
-static int ak4535_probe(struct platform_device *pdev) +static int __init ak4535_modinit(void) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct ak4535_setup_data *setup; - struct snd_soc_codec *codec; - struct ak4535_priv *ak4535; - int ret; - - printk(KERN_INFO "AK4535 Audio Codec %s", AK4535_VERSION); - - setup = socdev->codec_data; - codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); - if (codec == NULL) - return -ENOMEM; - - ak4535 = kzalloc(sizeof(struct ak4535_priv), GFP_KERNEL); - if (ak4535 == NULL) { - kfree(codec); - return -ENOMEM; - } - - snd_soc_codec_set_drvdata(codec, ak4535); - socdev->card->codec = codec; - mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - ak4535_socdev = socdev; - ret = -ENODEV; - + int ret = 0; #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) - if (setup->i2c_address) { - codec->hw_write = (hw_write_t)i2c_master_send; - ret = ak4535_add_i2c_device(pdev, setup); - } -#endif - + ret = i2c_add_driver(&ak4535_i2c_driver); if (ret != 0) { - kfree(snd_soc_codec_get_drvdata(codec)); - kfree(codec); + printk(KERN_ERR "Failed to register AK4535 I2C driver: %d\n", + ret); } +#endif return ret; } +module_init(ak4535_modinit);
-/* power down chip */ -static int ak4535_remove(struct platform_device *pdev) +static void __exit ak4535_exit(void) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - - if (codec->control_data) - ak4535_set_bias_level(codec, SND_SOC_BIAS_OFF); - - snd_soc_free_pcms(socdev); - snd_soc_dapm_free(socdev); #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) - if (codec->control_data) - i2c_unregister_device(codec->control_data); i2c_del_driver(&ak4535_i2c_driver); #endif - kfree(snd_soc_codec_get_drvdata(codec)); - kfree(codec); - - return 0; -} - -struct snd_soc_codec_device soc_codec_dev_ak4535 = { - .probe = ak4535_probe, - .remove = ak4535_remove, - .suspend = ak4535_suspend, - .resume = ak4535_resume, -}; -EXPORT_SYMBOL_GPL(soc_codec_dev_ak4535); - -static int __init ak4535_modinit(void) -{ - return snd_soc_register_dai(&ak4535_dai); -} -module_init(ak4535_modinit); - -static void __exit ak4535_exit(void) -{ - snd_soc_unregister_dai(&ak4535_dai); } module_exit(ak4535_exit);
diff --git a/sound/soc/codecs/ak4535.h b/sound/soc/codecs/ak4535.h index c7a5870..0358f48 100644 --- a/sound/soc/codecs/ak4535.h +++ b/sound/soc/codecs/ak4535.h @@ -36,12 +36,7 @@
#define AK4535_CACHEREGNUM 0x10
-struct ak4535_setup_data { - int i2c_bus; - unsigned short i2c_address; -}; - -extern struct snd_soc_dai ak4535_dai; -extern struct snd_soc_codec_device soc_codec_dev_ak4535; +extern struct snd_soc_dai_driver ak4535_dai; +extern struct snd_soc_codec_driver soc_codec_dev_ak4535;
#endif diff --git a/sound/soc/codecs/ak4642.c b/sound/soc/codecs/ak4642.c index 8d56811..1f1a955 100644 --- a/sound/soc/codecs/ak4642.c +++ b/sound/soc/codecs/ak4642.c @@ -101,15 +101,14 @@ #define FS3 (1 << 5) #define FS_MASK (FS0 | FS1 | FS2 | FS3)
-struct snd_soc_codec_device soc_codec_dev_ak4642;
/* codec private data */ struct ak4642_priv { - struct snd_soc_codec codec; + unsigned int sysclk; + enum snd_soc_control_type control_type; + void *control_data; };
-static struct snd_soc_codec *ak4642_codec; - /* * ak4642 register cache */ @@ -378,7 +377,7 @@ static struct snd_soc_dai_ops ak4642_dai_ops = { .hw_params = ak4642_dai_hw_params, };
-struct snd_soc_dai ak4642_dai = { +struct snd_soc_dai_driver ak4642_dai = { .name = "AK4642", .playback = { .stream_name = "Playback", @@ -397,108 +396,65 @@ struct snd_soc_dai ak4642_dai = { }; EXPORT_SYMBOL_GPL(ak4642_dai);
-static int ak4642_resume(struct platform_device *pdev) +static int ak4642_resume(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - ak4642_sync(codec); return 0; }
-/* - * initialise the AK4642 driver - * register the mixer and dsp interfaces with the kernel - */ -static int ak4642_init(struct ak4642_priv *ak4642) + +static int ak4642_probe(struct snd_soc_codec *codec) { - struct snd_soc_codec *codec = &ak4642->codec; - int ret = 0; + struct ak4642_priv *ak4642 = snd_soc_codec_get_drvdata(codec);
- if (ak4642_codec) { - dev_err(codec->dev, "Another ak4642 is registered\n"); - return -EINVAL; - } + dev_info(codec->dev, "AK4642 Audio Codec %s", AK4642_VERSION);
- mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - snd_soc_codec_set_drvdata(codec, ak4642); - codec->name = "AK4642"; - codec->owner = THIS_MODULE; - codec->read = ak4642_read_reg_cache; - codec->write = ak4642_write; - codec->dai = &ak4642_dai; - codec->num_dai = 1; codec->hw_write = (hw_write_t)i2c_master_send; - codec->reg_cache_size = ARRAY_SIZE(ak4642_reg); - codec->reg_cache = kmemdup(ak4642_reg, - sizeof(ak4642_reg), GFP_KERNEL); - - if (!codec->reg_cache) - return -ENOMEM; - - ak4642_dai.dev = codec->dev; - ak4642_codec = codec; + codec->control_data = ak4642->control_data;
- ret = snd_soc_register_codec(codec); - if (ret) { - dev_err(codec->dev, "Failed to register codec: %d\n", ret); - goto reg_cache_err; - } - - ret = snd_soc_register_dai(&ak4642_dai); - if (ret) { - dev_err(codec->dev, "Failed to register DAI: %d\n", ret); - snd_soc_unregister_codec(codec); - goto reg_cache_err; - }
- return ret; - -reg_cache_err: - kfree(codec->reg_cache); - codec->reg_cache = NULL; - - return ret; + return 0; }
+struct snd_soc_codec_driver soc_codec_dev_ak4642 = { + .name = "AK4642", + .probe = ak4642_probe, + .resume = ak4642_resume, + .owner = THIS_MODULE, + .read = ak4642_read_reg_cache, + .write = ak4642_write, + .reg_cache_size = ARRAY_SIZE(ak4642_reg), + .reg_word_size = sizeof(u8), + .reg_cache_default = ak4642_reg, +}; +EXPORT_SYMBOL_GPL(soc_codec_dev_ak4642); + #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) -static int ak4642_i2c_probe(struct i2c_client *i2c, - const struct i2c_device_id *id) +static __devinit int ak4642_i2c_probe(struct i2c_client *i2c, + const struct i2c_device_id *id) { struct ak4642_priv *ak4642; - struct snd_soc_codec *codec; int ret;
ak4642 = kzalloc(sizeof(struct ak4642_priv), GFP_KERNEL); - if (!ak4642) + if (ak4642 == NULL) return -ENOMEM;
- codec = &ak4642->codec; - codec->dev = &i2c->dev; - i2c_set_clientdata(i2c, ak4642); - codec->control_data = i2c; + ak4642->control_data = i2c; + ak4642->control_type = SND_SOC_I2C;
- ret = ak4642_init(ak4642); + ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &soc_codec_dev_ak4642, &ak4642_dai, 1); if (ret < 0) - printk(KERN_ERR "failed to initialise AK4642\n"); - + kfree(ak4642); return ret; }
-static int ak4642_i2c_remove(struct i2c_client *client) +static __devexit int ak4642_i2c_remove(struct i2c_client *client) { - struct ak4642_priv *ak4642 = i2c_get_clientdata(client); - - snd_soc_unregister_dai(&ak4642_dai); - snd_soc_unregister_codec(&ak4642->codec); - kfree(ak4642->codec.reg_cache); - kfree(ak4642); - ak4642_codec = NULL; - + snd_soc_unregister_codec(&client->dev, client->addr); + kfree(i2c_get_clientdata(client)); return 0; }
@@ -514,58 +470,12 @@ static struct i2c_driver ak4642_i2c_driver = { .name = "AK4642 I2C Codec", .owner = THIS_MODULE, }, - .probe = ak4642_i2c_probe, - .remove = ak4642_i2c_remove, - .id_table = ak4642_i2c_id, + .probe = ak4642_i2c_probe, + .remove = __devexit_p(ak4642_i2c_remove), + .id_table = ak4642_i2c_id, }; - #endif
-static int ak4642_probe(struct platform_device *pdev) -{ - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - int ret; - - if (!ak4642_codec) { - dev_err(&pdev->dev, "Codec device not registered\n"); - return -ENODEV; - } - - socdev->card->codec = ak4642_codec; - - /* register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret < 0) { - printk(KERN_ERR "ak4642: failed to create pcms\n"); - goto pcm_err; - } - - dev_info(&pdev->dev, "AK4642 Audio Codec %s", AK4642_VERSION); - return ret; - -pcm_err: - return ret; - -} - -/* power down chip */ -static int ak4642_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_ak4642 = { - .probe = ak4642_probe, - .remove = ak4642_remove, - .resume = ak4642_resume, -}; -EXPORT_SYMBOL_GPL(soc_codec_dev_ak4642); - static int __init ak4642_modinit(void) { int ret = 0; diff --git a/sound/soc/codecs/ak4642.h b/sound/soc/codecs/ak4642.h index e476833..d5a9e43 100644 --- a/sound/soc/codecs/ak4642.h +++ b/sound/soc/codecs/ak4642.h @@ -14,7 +14,7 @@ #ifndef _AK4642_H #define _AK4642_H
-extern struct snd_soc_dai ak4642_dai; -extern struct snd_soc_codec_device soc_codec_dev_ak4642; +extern struct snd_soc_dai_driver ak4642_dai; +extern struct snd_soc_codec_driver soc_codec_dev_ak4642;
#endif diff --git a/sound/soc/codecs/ak4671.c b/sound/soc/codecs/ak4671.c index 8756693..1921fc4 100644 --- a/sound/soc/codecs/ak4671.c +++ b/sound/soc/codecs/ak4671.c @@ -23,11 +23,11 @@
#include "ak4671.h"
-static struct snd_soc_codec *ak4671_codec;
/* codec private data */ struct ak4671_priv { - struct snd_soc_codec codec; + enum snd_soc_control_type control_type; + void *control_data; u8 reg_cache[AK4671_CACHEREGNUM]; };
@@ -619,7 +619,7 @@ static struct snd_soc_dai_ops ak4671_dai_ops = { .set_fmt = ak4671_set_dai_fmt, };
-struct snd_soc_dai ak4671_dai = { +struct snd_soc_dai_driver ak4671_dai = { .name = "AK4671", .playback = { .stream_name = "Playback", @@ -637,25 +637,18 @@ struct snd_soc_dai ak4671_dai = { }; EXPORT_SYMBOL_GPL(ak4671_dai);
-static int ak4671_probe(struct platform_device *pdev) +static int ak4671_probe(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - int ret = 0; - - if (ak4671_codec == NULL) { - dev_err(&pdev->dev, "Codec device not registered\n"); - return -ENODEV; - } + struct ak4671_priv *ak4671 = snd_soc_codec_get_drvdata(codec); + int ret;
- socdev->card->codec = ak4671_codec; - codec = ak4671_codec; + codec->hw_write = (hw_write_t)i2c_master_send; + codec->bias_level = SND_SOC_BIAS_OFF;
- /* register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); + ret = snd_soc_codec_set_cache_io(codec, 8, 8, ak4671->control_type); if (ret < 0) { - dev_err(codec->dev, "failed to create pcms: %d\n", ret); - goto pcm_err; + dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); + return ret; }
snd_soc_add_controls(codec, ak4671_snd_controls, @@ -665,121 +658,51 @@ static int ak4671_probe(struct platform_device *pdev) ak4671_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
return ret; - -pcm_err: - return ret; }
-static int ak4671_remove(struct platform_device *pdev) +static int ak4671_remove(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - - snd_soc_free_pcms(socdev); - snd_soc_dapm_free(socdev); - + ak4671_set_bias_level(codec, SND_SOC_BIAS_OFF); return 0; }
-struct snd_soc_codec_device soc_codec_dev_ak4671 = { +struct snd_soc_codec_driver soc_codec_dev_ak4671 = { + .name = "AK4671", + .owner = THIS_MODULE, .probe = ak4671_probe, .remove = ak4671_remove, + .set_bias_level = ak4671_set_bias_level, + .reg_cache_size = AK4671_CACHEREGNUM, + .reg_word_size = sizeof(u8), + .reg_cache_default = ak4671_reg, }; EXPORT_SYMBOL_GPL(soc_codec_dev_ak4671);
-static int ak4671_register(struct ak4671_priv *ak4671, - enum snd_soc_control_type control) -{ - int ret; - struct snd_soc_codec *codec = &ak4671->codec; - - if (ak4671_codec) { - dev_err(codec->dev, "Another AK4671 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, ak4671); - codec->name = "AK4671"; - codec->owner = THIS_MODULE; - codec->bias_level = SND_SOC_BIAS_OFF; - codec->set_bias_level = ak4671_set_bias_level; - codec->dai = &ak4671_dai; - codec->num_dai = 1; - codec->reg_cache_size = AK4671_CACHEREGNUM; - codec->reg_cache = &ak4671->reg_cache; - - memcpy(codec->reg_cache, ak4671_reg, sizeof(ak4671_reg)); - - ret = snd_soc_codec_set_cache_io(codec, 8, 8, control); - if (ret < 0) { - dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); - goto err; - } - - ak4671_dai.dev = codec->dev; - ak4671_codec = codec; - - ret = snd_soc_register_codec(codec); - if (ret != 0) { - dev_err(codec->dev, "Failed to register codec: %d\n", ret); - goto err; - } - - ret = snd_soc_register_dai(&ak4671_dai); - if (ret != 0) { - dev_err(codec->dev, "Failed to register DAI: %d\n", ret); - goto err_codec; - } - - return 0; - -err_codec: - snd_soc_unregister_codec(codec); -err: - kfree(ak4671); - return ret; -} - -static void ak4671_unregister(struct ak4671_priv *ak4671) -{ - ak4671_set_bias_level(&ak4671->codec, SND_SOC_BIAS_OFF); - snd_soc_unregister_dai(&ak4671_dai); - snd_soc_unregister_codec(&ak4671->codec); - kfree(ak4671); - ak4671_codec = NULL; -} - static int __devinit ak4671_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct ak4671_priv *ak4671; - struct snd_soc_codec *codec; + int ret;
ak4671 = kzalloc(sizeof(struct ak4671_priv), GFP_KERNEL); if (ak4671 == NULL) return -ENOMEM;
- codec = &ak4671->codec; - codec->hw_write = (hw_write_t)i2c_master_send; - i2c_set_clientdata(client, ak4671); - codec->control_data = client; - - codec->dev = &client->dev; + ak4671->control_data = client; + ak4671->control_type = SND_SOC_I2C;
- return ak4671_register(ak4671, SND_SOC_I2C); + ret = snd_soc_register_codec(&client->dev, client->addr, + &soc_codec_dev_ak4671, &ak4671_dai, 1); + if (ret < 0) + kfree(ak4671); + return ret; }
static __devexit int ak4671_i2c_remove(struct i2c_client *client) { - struct ak4671_priv *ak4671 = i2c_get_clientdata(client); - - ak4671_unregister(ak4671); - + snd_soc_unregister_codec(&client->dev, client->addr); + kfree(i2c_get_clientdata(client)); return 0; }
diff --git a/sound/soc/codecs/ak4671.h b/sound/soc/codecs/ak4671.h index e2fad96..73f862c 100644 --- a/sound/soc/codecs/ak4671.h +++ b/sound/soc/codecs/ak4671.h @@ -150,7 +150,7 @@ /* AK4671_LOUT2_POWER_MANAGEMENT (0x10) Fields */ #define AK4671_MUTEN 0x04
-extern struct snd_soc_dai ak4671_dai; -extern struct snd_soc_codec_device soc_codec_dev_ak4671; +extern struct snd_soc_dai_driver ak4671_dai; +extern struct snd_soc_codec_driver soc_codec_dev_ak4671;
#endif
On Fri, 2010-06-25 at 18:52 +0100, Liam Girdwood wrote:
Move AKM CODECs to multi-component model.
This patch changes the probe() and remove() of the CODEC drivers as follows:-
o Make CODEC driver a platform device (non MFD codecs only)
Oops, thought I'd removed the text in parenthesis. *All* CODECs are now platform drivers.
Liam
Move codecs to multi-component model.
This patch changes the probe() and remove() of the CODEC drivers as follows:-
o Make CODEC driver a platform device (non MFD codecs only) o Moved all struct snd_soc_codec list, mutex, etc initialiasation to core. o Removed all static codec pointers (drivers now support > 1 codec dev) o snd_soc_register_pcms() now done by core. o snd_soc_register_dai() folded into snd_soc_register_codec(). o codec cache can now be malloc()ed by core.
Other required changes due to multi-component model :-
o cs42151 and cs4270: set_dai_sysclk() - we no longer change static _driver_ rates on clock changes (as the driver can be used by other cs24xx codec devices). The codec device rate is checked at hw_params() time.
Signed-off-by: Liam Girdwood lrg@slimlogic.co.uk --- sound/soc/codecs/cs4270.c | 390 ++++++++++++++++---------------------------- sound/soc/codecs/cs4270.h | 4 +- sound/soc/codecs/cs42l51.c | 292 +++++++++++---------------------- sound/soc/codecs/cs42l51.h | 4 +- sound/soc/codecs/da7210.c | 145 ++++------------- sound/soc/codecs/da7210.h | 4 +- 6 files changed, 270 insertions(+), 569 deletions(-)
diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c index 30d9492..8d3a3af 100644 --- a/sound/soc/codecs/cs4270.c +++ b/sound/soc/codecs/cs4270.c @@ -114,7 +114,8 @@ static const char *supply_names[] = {
/* Private data for the CS4270 */ struct cs4270_private { - struct snd_soc_codec codec; + enum snd_soc_control_type control_type; + void *control_data; u8 reg_cache[CS4270_NUMREGS]; unsigned int mclk; /* Input frequency of the MCLK pin */ unsigned int mode; /* The mode (I2S or left-justified) */ @@ -212,44 +213,8 @@ static int cs4270_set_dai_sysclk(struct snd_soc_dai *codec_dai, { struct snd_soc_codec *codec = codec_dai->codec; struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec); - unsigned int rates = 0; - unsigned int rate_min = -1; - unsigned int rate_max = 0; - unsigned int i;
cs4270->mclk = freq; - - if (cs4270->mclk) { - for (i = 0; i < NUM_MCLK_RATIOS; i++) { - unsigned int rate = freq / cs4270_mode_ratios[i].ratio; - rates |= snd_pcm_rate_to_rate_bit(rate); - if (rate < rate_min) - rate_min = rate; - if (rate > rate_max) - rate_max = rate; - } - /* FIXME: soc should support a rate list */ - rates &= ~SNDRV_PCM_RATE_KNOT; - - if (!rates) { - dev_err(codec->dev, "could not find a valid sample rate\n"); - return -EINVAL; - } - } else { - /* enable all possible rates */ - rates = SNDRV_PCM_RATE_8000_192000; - rate_min = 8000; - rate_max = 192000; - } - - codec_dai->playback.rates = rates; - codec_dai->playback.rate_min = rate_min; - codec_dai->playback.rate_max = rate_max; - - codec_dai->capture.rates = rates; - codec_dai->capture.rate_min = rate_min; - codec_dai->capture.rate_max = rate_max; - return 0; }
@@ -410,8 +375,7 @@ static int cs4270_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 cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec); int ret; unsigned int i; @@ -549,19 +513,6 @@ static const struct snd_kcontrol_new cs4270_snd_controls[] = { snd_soc_get_volsw, cs4270_soc_put_mute), };
-/* - * cs4270_codec - global variable to store codec for the ASoC probe function - * - * If struct i2c_driver had a private_data field, we wouldn't need to use - * cs4270_codec. This is the only way to pass the codec structure from - * cs4270_i2c_probe() to cs4270_probe(). Unfortunately, there is no good - * way to synchronize these two functions. cs4270_i2c_probe() can be called - * multiple times before cs4270_probe() is called even once. So for now, we - * also only allow cs4270_i2c_probe() to be run once. That means that we do - * not support more than one cs4270 device in the system, at least for now. - */ -static struct snd_soc_codec *cs4270_codec; - static struct snd_soc_dai_ops cs4270_dai_ops = { .hw_params = cs4270_hw_params, .set_sysclk = cs4270_set_dai_sysclk, @@ -569,20 +520,24 @@ static struct snd_soc_dai_ops cs4270_dai_ops = { .digital_mute = cs4270_dai_mute, };
-struct snd_soc_dai cs4270_dai = { +struct snd_soc_dai_driver cs4270_dai = { .name = "cs4270", .playback = { .stream_name = "Playback", .channels_min = 1, .channels_max = 2, - .rates = 0, + .rates = SNDRV_PCM_RATE_CONTINUOUS, + .rate_min = 4000, + .rate_max = 216000, .formats = CS4270_FORMATS, }, .capture = { .stream_name = "Capture", .channels_min = 1, .channels_max = 2, - .rates = 0, + .rates = SNDRV_PCM_RATE_CONTINUOUS, + .rate_min = 4000, + .rate_max = 216000, .formats = CS4270_FORMATS, }, .ops = &cs4270_dai_ops, @@ -596,20 +551,46 @@ EXPORT_SYMBOL_GPL(cs4270_dai); * This function is called when ASoC has all the pieces it needs to * instantiate a sound driver. */ -static int cs4270_probe(struct platform_device *pdev) +static int cs4270_probe(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = cs4270_codec; struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec); - int i, ret; + int i, ret, reg; + + codec->control_data = cs4270->control_data; + + /* The I2C interface is set up, so pre-fill our register cache */ + + ret = cs4270_fill_cache(codec); + if (ret < 0) { + dev_err(codec->dev, "failed to fill register cache\n"); + return ret; + } + + /* Disable auto-mute. This feature appears to be buggy. In some + * situations, auto-mute will not deactivate when it should, so we want + * this feature disabled by default. An application (e.g. alsactl) can + * re-enabled it by using the controls. + */ + + reg = cs4270_read_reg_cache(codec, CS4270_MUTE); + reg &= ~CS4270_MUTE_AUTO; + ret = cs4270_i2c_write(codec, CS4270_MUTE, reg); + if (ret < 0) { + dev_err(codec->dev, "i2c write failed\n"); + return ret; + }
- /* Connect the codec to the socdev. snd_soc_new_pcms() needs this. */ - socdev->card->codec = codec; + /* Disable automatic volume control. The hardware enables, and it + * causes volume change commands to be delayed, sometimes until after + * playback has started. An application (e.g. alsactl) can + * re-enabled it by using the controls. + */
- /* Register PCMs */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); + reg = cs4270_read_reg_cache(codec, CS4270_TRANS); + reg &= ~(CS4270_TRANS_SOFT | CS4270_TRANS_ZERO); + ret = cs4270_i2c_write(codec, CS4270_TRANS, reg); if (ret < 0) { - dev_err(codec->dev, "failed to create pcms\n"); + dev_err(codec->dev, "i2c write failed\n"); return ret; }
@@ -618,7 +599,7 @@ static int cs4270_probe(struct platform_device *pdev) ARRAY_SIZE(cs4270_snd_controls)); if (ret < 0) { dev_err(codec->dev, "failed to add controls\n"); - goto error_free_pcms; + return ret; }
/* get the power supply regulators */ @@ -628,7 +609,7 @@ static int cs4270_probe(struct platform_device *pdev) ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(cs4270->supplies), cs4270->supplies); if (ret < 0) - goto error_free_pcms; + return ret;
ret = regulator_bulk_enable(ARRAY_SIZE(cs4270->supplies), cs4270->supplies); @@ -641,9 +622,6 @@ error_free_regulators: regulator_bulk_free(ARRAY_SIZE(cs4270->supplies), cs4270->supplies);
-error_free_pcms: - snd_soc_free_pcms(socdev); - return ret; }
@@ -653,19 +631,100 @@ error_free_pcms: * * This function is the counterpart to cs4270_probe(). */ -static int cs4270_remove(struct platform_device *pdev) +static int cs4270_remove(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = cs4270_codec; struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
- snd_soc_free_pcms(socdev); regulator_bulk_disable(ARRAY_SIZE(cs4270->supplies), cs4270->supplies); regulator_bulk_free(ARRAY_SIZE(cs4270->supplies), cs4270->supplies);
return 0; };
+#ifdef CONFIG_PM + +/* This suspend/resume implementation can handle both - a simple standby + * where the codec remains powered, and a full suspend, where the voltage + * domain the codec is connected to is teared down and/or any other hardware + * reset condition is asserted. + * + * The codec's own power saving features are enabled in the suspend callback, + * and all registers are written back to the hardware when resuming. + */ + +static int cs4270_soc_suspend(struct snd_soc_codec *codec, pm_message_t mesg) +{ + struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec); + int reg, ret; + + reg = snd_soc_read(codec, CS4270_PWRCTL) | CS4270_PWRCTL_PDN_ALL; + if (reg < 0) + return reg; + + ret = snd_soc_write(codec, CS4270_PWRCTL, reg); + if (ret < 0) + return ret; + + regulator_bulk_disable(ARRAY_SIZE(cs4270->supplies), + cs4270->supplies); + + return 0; +} + +static int cs4270_soc_resume(struct snd_soc_codec *codec) +{ + struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec); + struct i2c_client *i2c_client = codec->control_data; + int reg; + + regulator_bulk_enable(ARRAY_SIZE(cs4270->supplies), + cs4270->supplies); + + /* In case the device was put to hard reset during sleep, we need to + * wait 500ns here before any I2C communication. */ + ndelay(500); + + /* first restore the entire register cache ... */ + for (reg = CS4270_FIRSTREG; reg <= CS4270_LASTREG; reg++) { + u8 val = snd_soc_read(codec, reg); + + if (i2c_smbus_write_byte_data(i2c_client, reg, val)) { + dev_err(codec->dev, "i2c write failed\n"); + return -EIO; + } + } + + /* ... then disable the power-down bits */ + reg = snd_soc_read(codec, CS4270_PWRCTL); + reg &= ~CS4270_PWRCTL_PDN_ALL; + + return snd_soc_write(codec, CS4270_PWRCTL, reg); +} +#else +#define cs4270_soc_suspend NULL +#define cs4270_soc_resume NULL +#endif /* CONFIG_PM */ + +/* + * ASoC codec device structure + * + * Assign this variable to the codec_dev field of the machine driver's + * snd_soc_device structure. + */ +struct snd_soc_codec_driver soc_codec_device_cs4270 = { + .name = "CS4270", + .owner = THIS_MODULE, + .probe = cs4270_probe, + .remove = cs4270_remove, + .suspend = cs4270_soc_suspend, + .resume = cs4270_soc_resume, + .read = cs4270_read_reg_cache, + .write = cs4270_i2c_write, + .reg_cache_size = CS4270_NUMREGS, + .reg_word_size = sizeof(u8), +}; +EXPORT_SYMBOL_GPL(soc_codec_device_cs4270); + /** * cs4270_i2c_probe - initialize the I2C interface of the CS4270 * @i2c_client: the I2C client object @@ -677,22 +736,9 @@ static int cs4270_remove(struct platform_device *pdev) static int cs4270_i2c_probe(struct i2c_client *i2c_client, const struct i2c_device_id *id) { - struct snd_soc_codec *codec; struct cs4270_private *cs4270; - unsigned int reg; int ret;
- /* For now, we only support one cs4270 device in the system. See the - * comment for cs4270_codec. - */ - if (cs4270_codec) { - dev_err(&i2c_client->dev, "ignoring CS4270 at addr %X\n", - i2c_client->addr); - dev_err(&i2c_client->dev, "only one per board allowed\n"); - /* Should we return something other than ENODEV here? */ - return -ENODEV; - } - /* Verify that we have a CS4270 */
ret = i2c_smbus_read_byte_data(i2c_client, CS4270_CHIPID); @@ -719,87 +765,15 @@ static int cs4270_i2c_probe(struct i2c_client *i2c_client, dev_err(&i2c_client->dev, "could not allocate codec\n"); return -ENOMEM; } - codec = &cs4270->codec; - - mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - codec->dev = &i2c_client->dev; - codec->name = "CS4270"; - codec->owner = THIS_MODULE; - codec->dai = &cs4270_dai; - codec->num_dai = 1; - snd_soc_codec_set_drvdata(codec, cs4270); - codec->control_data = i2c_client; - codec->read = cs4270_read_reg_cache; - codec->write = cs4270_i2c_write; - codec->reg_cache = cs4270->reg_cache; - codec->reg_cache_size = CS4270_NUMREGS; - - /* The I2C interface is set up, so pre-fill our register cache */ - - ret = cs4270_fill_cache(codec); - if (ret < 0) { - dev_err(&i2c_client->dev, "failed to fill register cache\n"); - goto error_free_codec; - } - - /* Disable auto-mute. This feature appears to be buggy. In some - * situations, auto-mute will not deactivate when it should, so we want - * this feature disabled by default. An application (e.g. alsactl) can - * re-enabled it by using the controls. - */ - - reg = cs4270_read_reg_cache(codec, CS4270_MUTE); - reg &= ~CS4270_MUTE_AUTO; - ret = cs4270_i2c_write(codec, CS4270_MUTE, reg); - if (ret < 0) { - dev_err(&i2c_client->dev, "i2c write failed\n"); - return ret; - } - - /* Disable automatic volume control. The hardware enables, and it - * causes volume change commands to be delayed, sometimes until after - * playback has started. An application (e.g. alsactl) can - * re-enabled it by using the controls. - */ - - reg = cs4270_read_reg_cache(codec, CS4270_TRANS); - reg &= ~(CS4270_TRANS_SOFT | CS4270_TRANS_ZERO); - ret = cs4270_i2c_write(codec, CS4270_TRANS, reg); - if (ret < 0) { - dev_err(&i2c_client->dev, "i2c write failed\n"); - return ret; - } - - /* Initialize the DAI. Normally, we'd prefer to have a kmalloc'd DAI - * structure for each CS4270 device, but the machine driver needs to - * have a pointer to the DAI structure, so for now it must be a global - * variable. - */ - cs4270_dai.dev = &i2c_client->dev; - - /* Register the DAI. If all the other ASoC driver have already - * registered, then this will call our probe function, so - * cs4270_codec needs to be ready. - */ - cs4270_codec = codec; - ret = snd_soc_register_dai(&cs4270_dai); - if (ret < 0) { - dev_err(&i2c_client->dev, "failed to register DAIe\n"); - goto error_free_codec; - }
i2c_set_clientdata(i2c_client, cs4270); + cs4270->control_data = i2c_client; + cs4270->control_type = SND_SOC_I2C;
- return 0; - -error_free_codec: - kfree(cs4270); - cs4270_codec = NULL; - cs4270_dai.dev = NULL; - + ret = snd_soc_register_codec(&i2c_client->dev, i2c_client->addr, + &soc_codec_device_cs4270, &cs4270_dai, 1); + if (ret < 0) + kfree(cs4270); return ret; }
@@ -811,12 +785,8 @@ error_free_codec: */ static int cs4270_i2c_remove(struct i2c_client *i2c_client) { - struct cs4270_private *cs4270 = i2c_get_clientdata(i2c_client); - - kfree(cs4270); - cs4270_codec = NULL; - cs4270_dai.dev = NULL; - + snd_soc_unregister_codec(&i2c_client->dev, i2c_client->addr); + kfree(i2c_get_clientdata(i2c_client)); return 0; }
@@ -829,72 +799,6 @@ static struct i2c_device_id cs4270_id[] = { }; MODULE_DEVICE_TABLE(i2c, cs4270_id);
-#ifdef CONFIG_PM - -/* This suspend/resume implementation can handle both - a simple standby - * where the codec remains powered, and a full suspend, where the voltage - * domain the codec is connected to is teared down and/or any other hardware - * reset condition is asserted. - * - * The codec's own power saving features are enabled in the suspend callback, - * and all registers are written back to the hardware when resuming. - */ - -static int cs4270_soc_suspend(struct platform_device *pdev, pm_message_t mesg) -{ - struct snd_soc_codec *codec = cs4270_codec; - struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec); - int reg, ret; - - reg = snd_soc_read(codec, CS4270_PWRCTL) | CS4270_PWRCTL_PDN_ALL; - if (reg < 0) - return reg; - - ret = snd_soc_write(codec, CS4270_PWRCTL, reg); - if (ret < 0) - return ret; - - regulator_bulk_disable(ARRAY_SIZE(cs4270->supplies), - cs4270->supplies); - - return 0; -} - -static int cs4270_soc_resume(struct platform_device *pdev) -{ - struct snd_soc_codec *codec = cs4270_codec; - struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec); - struct i2c_client *i2c_client = codec->control_data; - int reg; - - regulator_bulk_enable(ARRAY_SIZE(cs4270->supplies), - cs4270->supplies); - - /* In case the device was put to hard reset during sleep, we need to - * wait 500ns here before any I2C communication. */ - ndelay(500); - - /* first restore the entire register cache ... */ - for (reg = CS4270_FIRSTREG; reg <= CS4270_LASTREG; reg++) { - u8 val = snd_soc_read(codec, reg); - - if (i2c_smbus_write_byte_data(i2c_client, reg, val)) { - dev_err(codec->dev, "i2c write failed\n"); - return -EIO; - } - } - - /* ... then disable the power-down bits */ - reg = snd_soc_read(codec, CS4270_PWRCTL); - reg &= ~CS4270_PWRCTL_PDN_ALL; - - return snd_soc_write(codec, CS4270_PWRCTL, reg); -} -#else -#define cs4270_soc_suspend NULL -#define cs4270_soc_resume NULL -#endif /* CONFIG_PM */ - /* * cs4270_i2c_driver - I2C device identification * @@ -911,20 +815,6 @@ static struct i2c_driver cs4270_i2c_driver = { .remove = cs4270_i2c_remove, };
-/* - * ASoC codec device structure - * - * Assign this variable to the codec_dev field of the machine driver's - * snd_soc_device structure. - */ -struct snd_soc_codec_device soc_codec_device_cs4270 = { - .probe = cs4270_probe, - .remove = cs4270_remove, - .suspend = cs4270_soc_suspend, - .resume = cs4270_soc_resume, -}; -EXPORT_SYMBOL_GPL(soc_codec_device_cs4270); - static int __init cs4270_init(void) { pr_info("Cirrus Logic CS4270 ALSA SoC Codec Driver\n"); diff --git a/sound/soc/codecs/cs4270.h b/sound/soc/codecs/cs4270.h index adc6cd9..19d3009 100644 --- a/sound/soc/codecs/cs4270.h +++ b/sound/soc/codecs/cs4270.h @@ -16,13 +16,13 @@ * The ASoC codec DAI structure for the CS4270. Assign this structure to * the .codec_dai field of your machine driver's snd_soc_dai_link structure. */ -extern struct snd_soc_dai cs4270_dai; +extern struct snd_soc_dai_driver cs4270_dai;
/* * The ASoC codec device structure for the CS4270. Assign this structure * to the .codec_dev field of your machine driver's snd_soc_device * structure. */ -extern struct snd_soc_codec_device soc_codec_device_cs4270; +extern struct snd_soc_codec_driver soc_codec_device_cs4270;
#endif diff --git a/sound/soc/codecs/cs42l51.c b/sound/soc/codecs/cs42l51.c index dd9b855..db26f51 100644 --- a/sound/soc/codecs/cs42l51.c +++ b/sound/soc/codecs/cs42l51.c @@ -42,15 +42,14 @@ enum master_slave_mode { };
struct cs42l51_private { + enum snd_soc_control_type control_type; + void *control_data; unsigned int mclk; unsigned int audio_mode; /* The mode (I2S or left-justified) */ enum master_slave_mode func; - struct snd_soc_codec codec; u8 reg_cache[CS42L51_NUMREGS]; };
-static struct snd_soc_codec *cs42l51_codec; - #define CS42L51_FORMATS ( \ SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | \ SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE | \ @@ -75,134 +74,6 @@ static int cs42l51_fill_cache(struct snd_soc_codec *codec) return 0; }
-static int cs42l51_i2c_probe(struct i2c_client *i2c_client, - const struct i2c_device_id *id) -{ - struct snd_soc_codec *codec; - struct cs42l51_private *cs42l51; - int ret = 0; - int reg; - - if (cs42l51_codec) - return -EBUSY; - - /* Verify that we have a CS42L51 */ - ret = i2c_smbus_read_byte_data(i2c_client, CS42L51_CHIP_REV_ID); - if (ret < 0) { - dev_err(&i2c_client->dev, "failed to read I2C\n"); - goto error; - } - - if ((ret != CS42L51_MK_CHIP_REV(CS42L51_CHIP_ID, CS42L51_CHIP_REV_A)) && - (ret != CS42L51_MK_CHIP_REV(CS42L51_CHIP_ID, CS42L51_CHIP_REV_B))) { - dev_err(&i2c_client->dev, "Invalid chip id\n"); - ret = -ENODEV; - goto error; - } - - dev_info(&i2c_client->dev, "found device cs42l51 rev %d\n", - ret & 7); - - cs42l51 = kzalloc(sizeof(struct cs42l51_private), GFP_KERNEL); - if (!cs42l51) { - dev_err(&i2c_client->dev, "could not allocate codec\n"); - return -ENOMEM; - } - codec = &cs42l51->codec; - - mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - codec->dev = &i2c_client->dev; - codec->name = "CS42L51"; - codec->owner = THIS_MODULE; - codec->dai = &cs42l51_dai; - codec->num_dai = 1; - snd_soc_codec_set_drvdata(codec, cs42l51); - - codec->control_data = i2c_client; - codec->reg_cache = cs42l51->reg_cache; - codec->reg_cache_size = CS42L51_NUMREGS; - i2c_set_clientdata(i2c_client, codec); - - ret = cs42l51_fill_cache(codec); - if (ret < 0) { - dev_err(&i2c_client->dev, "failed to fill register cache\n"); - goto error_alloc; - } - - ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C); - if (ret < 0) { - dev_err(&i2c_client->dev, "Failed to set cache I/O: %d\n", ret); - goto error_alloc; - } - - /* - * DAC configuration - * - Use signal processor - * - auto mute - * - vol changes immediate - * - no de-emphasize - */ - reg = CS42L51_DAC_CTL_DATA_SEL(1) - | CS42L51_DAC_CTL_AMUTE | CS42L51_DAC_CTL_DACSZ(0); - ret = snd_soc_write(codec, CS42L51_DAC_CTL, reg); - if (ret < 0) - goto error_alloc; - - cs42l51_dai.dev = codec->dev; - cs42l51_codec = codec; - - ret = snd_soc_register_codec(codec); - if (ret != 0) { - dev_err(codec->dev, "Failed to register codec: %d\n", ret); - goto error_alloc; - } - - ret = snd_soc_register_dai(&cs42l51_dai); - if (ret < 0) { - dev_err(&i2c_client->dev, "failed to register DAIe\n"); - goto error_reg; - } - - return 0; - -error_reg: - snd_soc_unregister_codec(codec); -error_alloc: - kfree(cs42l51); -error: - return ret; -} - -static int cs42l51_i2c_remove(struct i2c_client *client) -{ - struct cs42l51_private *cs42l51 = i2c_get_clientdata(client); - snd_soc_unregister_dai(&cs42l51_dai); - snd_soc_unregister_codec(cs42l51_codec); - cs42l51_codec = NULL; - kfree(cs42l51); - return 0; -} - - -static const struct i2c_device_id cs42l51_id[] = { - {"cs42l51", 0}, - {} -}; -MODULE_DEVICE_TABLE(i2c, cs42l51_id); - -static struct i2c_driver cs42l51_i2c_driver = { - .driver = { - .name = "CS42L51 I2C", - .owner = THIS_MODULE, - }, - .id_table = cs42l51_id, - .probe = cs42l51_i2c_probe, - .remove = cs42l51_i2c_remove, -}; - static int cs42l51_get_chan_mix(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { @@ -484,51 +355,8 @@ static int cs42l51_set_dai_sysclk(struct snd_soc_dai *codec_dai, { struct snd_soc_codec *codec = codec_dai->codec; struct cs42l51_private *cs42l51 = snd_soc_codec_get_drvdata(codec); - struct cs42l51_ratios *ratios = NULL; - int nr_ratios = 0; - unsigned int rates = 0; - unsigned int rate_min = -1; - unsigned int rate_max = 0; - int i;
cs42l51->mclk = freq; - - switch (cs42l51->func) { - case MODE_MASTER: - return -EINVAL; - case MODE_SLAVE: - ratios = slave_ratios; - nr_ratios = ARRAY_SIZE(slave_ratios); - break; - case MODE_SLAVE_AUTO: - ratios = slave_auto_ratios; - nr_ratios = ARRAY_SIZE(slave_auto_ratios); - break; - } - - for (i = 0; i < nr_ratios; i++) { - unsigned int rate = freq / ratios[i].ratio; - rates |= snd_pcm_rate_to_rate_bit(rate); - if (rate < rate_min) - rate_min = rate; - if (rate > rate_max) - rate_max = rate; - } - rates &= ~SNDRV_PCM_RATE_KNOT; - - if (!rates) { - dev_err(codec->dev, "could not find a valid sample rate\n"); - return -EINVAL; - } - - codec_dai->playback.rates = rates; - codec_dai->playback.rate_min = rate_min; - codec_dai->playback.rate_max = rate_max; - - codec_dai->capture.rates = rates; - codec_dai->capture.rate_min = rate_min; - codec_dai->capture.rate_max = rate_max; - return 0; }
@@ -537,8 +365,7 @@ static int cs42l51_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 cs42l51_private *cs42l51 = snd_soc_codec_get_drvdata(codec); int ret; unsigned int i; @@ -670,7 +497,7 @@ static struct snd_soc_dai_ops cs42l51_dai_ops = { .digital_mute = cs42l51_dai_mute, };
-struct snd_soc_dai cs42l51_dai = { +struct snd_soc_dai_driver cs42l51_dai = { .name = "CS42L51 HiFi", .playback = { .stream_name = "Playback", @@ -691,27 +518,38 @@ struct snd_soc_dai cs42l51_dai = { EXPORT_SYMBOL_GPL(cs42l51_dai);
-static int cs42l51_probe(struct platform_device *pdev) +static int cs42l51_probe(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - int ret = 0; + struct cs42l51_private *cs42l51 = snd_soc_codec_get_drvdata(codec); + int ret, reg;
- if (!cs42l51_codec) { - dev_err(&pdev->dev, "CS42L51 codec not yet registered\n"); - return -EINVAL; - } + codec->control_data = cs42l51->control_data;
- socdev->card->codec = cs42l51_codec; - codec = socdev->card->codec; + ret = cs42l51_fill_cache(codec); + if (ret < 0) { + dev_err(codec->dev, "failed to fill register cache\n"); + return ret; + }
- /* Register PCMs */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); + ret = snd_soc_codec_set_cache_io(codec, 8, 8, cs42l51->control_type); if (ret < 0) { - dev_err(&pdev->dev, "failed to create PCMs\n"); + dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); return ret; }
+ /* + * DAC configuration + * - Use signal processor + * - auto mute + * - vol changes immediate + * - no de-emphasize + */ + reg = CS42L51_DAC_CTL_DATA_SEL(1) + | CS42L51_DAC_CTL_AMUTE | CS42L51_DAC_CTL_DACSZ(0); + ret = snd_soc_write(codec, CS42L51_DAC_CTL, reg); + if (ret < 0) + return ret; + snd_soc_add_controls(codec, cs42l51_snd_controls, ARRAY_SIZE(cs42l51_snd_controls)); snd_soc_dapm_new_controls(codec, cs42l51_dapm_widgets, @@ -722,22 +560,80 @@ static int cs42l51_probe(struct platform_device *pdev) return 0; }
+struct snd_soc_codec_driver soc_codec_device_cs42l51 = { + .name = "CS42L51", + .owner = THIS_MODULE, + .probe = cs42l51_probe, + .reg_cache_size = CS42L51_NUMREGS, + .reg_word_size = sizeof(u8), +}; +EXPORT_SYMBOL_GPL(soc_codec_device_cs42l51);
-static int cs42l51_remove(struct platform_device *pdev) +static int cs42l51_i2c_probe(struct i2c_client *i2c_client, + const struct i2c_device_id *id) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); + struct cs42l51_private *cs42l51; + int ret; + + /* Verify that we have a CS42L51 */ + ret = i2c_smbus_read_byte_data(i2c_client, CS42L51_CHIP_REV_ID); + if (ret < 0) { + dev_err(&i2c_client->dev, "failed to read I2C\n"); + goto error; + } + + if ((ret != CS42L51_MK_CHIP_REV(CS42L51_CHIP_ID, CS42L51_CHIP_REV_A)) && + (ret != CS42L51_MK_CHIP_REV(CS42L51_CHIP_ID, CS42L51_CHIP_REV_B))) { + dev_err(&i2c_client->dev, "Invalid chip id\n"); + ret = -ENODEV; + goto error; + } + + dev_info(&i2c_client->dev, "found device cs42l51 rev %d\n", + ret & 7); + + cs42l51 = kzalloc(sizeof(struct cs42l51_private), GFP_KERNEL); + if (!cs42l51) { + dev_err(&i2c_client->dev, "could not allocate codec\n"); + return -ENOMEM; + } + + i2c_set_clientdata(i2c_client, cs42l51); + cs42l51->control_data = i2c_client; + cs42l51->control_type = SND_SOC_I2C; + + ret = snd_soc_register_codec(&i2c_client->dev, i2c_client->addr, + &soc_codec_device_cs42l51, &cs42l51_dai, 1); + if (ret < 0) + kfree(cs42l51); +error: + return ret; +}
- snd_soc_free_pcms(socdev); - snd_soc_dapm_free(socdev); +static int cs42l51_i2c_remove(struct i2c_client *client) +{ + struct cs42l51_private *cs42l51 = i2c_get_clientdata(client);
+ snd_soc_unregister_codec(&client->dev, client->addr); + kfree(cs42l51); return 0; }
-struct snd_soc_codec_device soc_codec_device_cs42l51 = { - .probe = cs42l51_probe, - .remove = cs42l51_remove +static const struct i2c_device_id cs42l51_id[] = { + {"cs42l51", 0}, + {} +}; +MODULE_DEVICE_TABLE(i2c, cs42l51_id); + +static struct i2c_driver cs42l51_i2c_driver = { + .driver = { + .name = "CS42L51 I2C", + .owner = THIS_MODULE, + }, + .id_table = cs42l51_id, + .probe = cs42l51_i2c_probe, + .remove = cs42l51_i2c_remove, }; -EXPORT_SYMBOL_GPL(soc_codec_device_cs42l51);
static int __init cs42l51_init(void) { diff --git a/sound/soc/codecs/cs42l51.h b/sound/soc/codecs/cs42l51.h index 8f0bd97..2144b90 100644 --- a/sound/soc/codecs/cs42l51.h +++ b/sound/soc/codecs/cs42l51.h @@ -158,6 +158,6 @@ #define CS42L51_LASTREG 0x20 #define CS42L51_NUMREGS (CS42L51_LASTREG - CS42L51_FIRSTREG + 1)
-extern struct snd_soc_dai cs42l51_dai; -extern struct snd_soc_codec_device soc_codec_device_cs42l51; +extern struct snd_soc_dai_driver cs42l51_dai; +extern struct snd_soc_codec_driver soc_codec_device_cs42l51; #endif diff --git a/sound/soc/codecs/da7210.c b/sound/soc/codecs/da7210.c index a83aa18..9c50db1 100644 --- a/sound/soc/codecs/da7210.c +++ b/sound/soc/codecs/da7210.c @@ -138,11 +138,10 @@
/* Codec private data */ struct da7210_priv { - struct snd_soc_codec codec; + enum snd_soc_control_type control_type; + void *control_data; };
-static struct snd_soc_codec *da7210_codec; - /* * Register cache */ @@ -185,12 +184,12 @@ static int da7210_write(struct snd_soc_codec *codec, u32 reg, u32 value) u8 *cache = codec->reg_cache; u8 data[2];
- BUG_ON(codec->volatile_register); + BUG_ON(codec->driver->volatile_register);
data[0] = reg & 0xff; data[1] = value & 0xff;
- if (reg >= codec->reg_cache_size) + if (reg >= codec->driver->reg_cache_size) return -EIO;
if (2 != codec->hw_write(codec->control_data, data, 2)) @@ -247,8 +246,7 @@ static int da7210_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; u32 dai_cfg1; u32 hpf_reg, hpf_mask, hpf_value; u32 fs, bypass; @@ -410,9 +408,8 @@ static struct snd_soc_dai_ops da7210_dai_ops = { .set_fmt = da7210_set_dai_fmt, };
-struct snd_soc_dai da7210_dai = { +struct snd_soc_dai_driver da7210_dai = { .name = "DA7210 IIS", - .id = 0, /* playback capabilities */ .playback = { .stream_name = "Playback", @@ -434,53 +431,14 @@ struct snd_soc_dai da7210_dai = { }; EXPORT_SYMBOL_GPL(da7210_dai);
-/* - * Initialize the DA7210 driver - * register the mixer and dsp interfaces with the kernel - */ -static int da7210_init(struct da7210_priv *da7210) +static int da7210_probe(struct snd_soc_codec *codec) { - struct snd_soc_codec *codec = &da7210->codec; - int ret = 0; + struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
- if (da7210_codec) { - dev_err(codec->dev, "Another da7210 is registered\n"); - return -EINVAL; - } + dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
- mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - snd_soc_codec_set_drvdata(codec, da7210); - codec->name = "DA7210"; - codec->owner = THIS_MODULE; - codec->read = da7210_read; - codec->write = da7210_write; - codec->dai = &da7210_dai; - codec->num_dai = 1; + codec->control_data = da7210->control_data; codec->hw_write = (hw_write_t)i2c_master_send; - codec->reg_cache_size = ARRAY_SIZE(da7210_reg); - codec->reg_cache = kmemdup(da7210_reg, - sizeof(da7210_reg), GFP_KERNEL); - - if (!codec->reg_cache) - return -ENOMEM; - - da7210_dai.dev = codec->dev; - da7210_codec = codec; - - ret = snd_soc_register_codec(codec); - if (ret) { - dev_err(codec->dev, "Failed to register CODEC: %d\n", ret); - goto init_err; - } - - ret = snd_soc_register_dai(&da7210_dai); - if (ret) { - dev_err(codec->dev, "Failed to register DAI: %d\n", ret); - goto init_err; - }
/* FIXME * @@ -563,50 +521,48 @@ static int da7210_init(struct da7210_priv *da7210) /* Activate all enabled subsystem */ da7210_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN);
- return ret; - -init_err: - kfree(codec->reg_cache); - codec->reg_cache = NULL; - - return ret; - + return 0; }
+struct snd_soc_codec_driver soc_codec_dev_da7210 = { + .name = "DA7210", + .owner = THIS_MODULE, + .probe = da7210_probe, + .read = da7210_read, + .write = da7210_write, + .reg_cache_size = ARRAY_SIZE(da7210_reg), + .reg_word_size = sizeof(u8), + .reg_cache_default = da7210_reg, +}; +EXPORT_SYMBOL_GPL(soc_codec_dev_da7210); + #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) static int __devinit da7210_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct da7210_priv *da7210; - struct snd_soc_codec *codec; int ret;
da7210 = kzalloc(sizeof(struct da7210_priv), GFP_KERNEL); if (!da7210) return -ENOMEM;
- codec = &da7210->codec; - codec->dev = &i2c->dev; - i2c_set_clientdata(i2c, da7210); - codec->control_data = i2c; + da7210->control_data = i2c; + da7210->control_type = SND_SOC_I2C;
- ret = da7210_init(da7210); + ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &soc_codec_dev_da7210, &da7210_dai, 1); if (ret < 0) - pr_err("Failed to initialise da7210 audio codec\n"); + kfree(da7210);
return ret; }
static int __devexit da7210_i2c_remove(struct i2c_client *client) { - struct da7210_priv *da7210 = i2c_get_clientdata(client); - - snd_soc_unregister_dai(&da7210_dai); - kfree(da7210->codec.reg_cache); - kfree(da7210); - da7210_codec = NULL; - + snd_soc_unregister_codec(&client->dev, client->addr); + kfree(i2c_get_clientdata(client)); return 0; }
@@ -628,47 +584,6 @@ static struct i2c_driver da7210_i2c_driver = { }; #endif
-static int da7210_probe(struct platform_device *pdev) -{ - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - int ret; - - if (!da7210_codec) { - dev_err(&pdev->dev, "Codec device not registered\n"); - return -ENODEV; - } - - socdev->card->codec = da7210_codec; - codec = da7210_codec; - - /* Register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret < 0) - goto pcm_err; - - dev_info(&pdev->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION); - -pcm_err: - return ret; -} - -static int da7210_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_da7210 = { - .probe = da7210_probe, - .remove = da7210_remove, -}; -EXPORT_SYMBOL_GPL(soc_codec_dev_da7210); - static int __init da7210_modinit(void) { int ret = 0; diff --git a/sound/soc/codecs/da7210.h b/sound/soc/codecs/da7210.h index 390d621..c530692 100644 --- a/sound/soc/codecs/da7210.h +++ b/sound/soc/codecs/da7210.h @@ -17,8 +17,8 @@ #ifndef _DA7210_H #define _DA7210_H
-extern struct snd_soc_dai da7210_dai; -extern struct snd_soc_codec_device soc_codec_dev_da7210; +extern struct snd_soc_dai_driver da7210_dai; +extern struct snd_soc_codec_driver soc_codec_dev_da7210;
#endif
On Fri, Jun 25, 2010 at 12:52 PM, Liam Girdwood lrg@slimlogic.co.uk wrote:
/* Private data for the CS4270 */ struct cs4270_private {
- struct snd_soc_codec codec;
- enum snd_soc_control_type control_type;
- void *control_data;
Because of this change, there is a comment later in the file that is no longer valid:
/* Allocate enough space for the snd_soc_codec structure and our private data together. */ cs4270 = kzalloc(sizeof(struct cs4270_private), GFP_KERNEL); if (!cs4270) { dev_err(&i2c_client->dev, "could not allocate codec\n"); return -ENOMEM; }
Other than that ...
CS4270 portions: Acked-by: Timur Tabi timur@freescale.com
On Fri, 2010-06-25 at 13:29 -0500, Timur Tabi wrote:
On Fri, Jun 25, 2010 at 12:52 PM, Liam Girdwood lrg@slimlogic.co.uk wrote:
/* Private data for the CS4270 */ struct cs4270_private {
struct snd_soc_codec codec;
enum snd_soc_control_type control_type;
void *control_data;
Because of this change, there is a comment later in the file that is no longer valid:
/* Allocate enough space for the snd_soc_codec structure and our private data together. */ cs4270 = kzalloc(sizeof(struct cs4270_private), GFP_KERNEL); if (!cs4270) { dev_err(&i2c_client->dev, "could not allocate codec\n"); return -ENOMEM; }
Other than that ...
CS4270 portions: Acked-by: Timur Tabi timur@freescale.com
Thanks, fixed.
Liam
Move CODECs to multi-component model.
This patch changes the probe() and remove() of the CODEC drivers as follows:-
o Make CODEC driver a platform device (non MFD codecs only) o Moved all struct snd_soc_codec list, mutex, etc initialiasation to core. o Removed all static codec pointers (drivers now support > 1 codec dev) o snd_soc_register_pcms() now done by core. o snd_soc_register_dai() folded into snd_soc_register_codec(). o codec cache can now be malloc()ed by core.
Other required changes due to multi-component model :-
Signed-off-by: Liam Girdwood lrg@slimlogic.co.uk --- sound/soc/codecs/jz4740.c | 114 ++++++------------------ sound/soc/codecs/jz4740.h | 4 +- sound/soc/codecs/pcm3008.c | 90 ++++++++---------- sound/soc/codecs/pcm3008.h | 4 +- sound/soc/codecs/ssm2602.c | 217 ++++++++++++-------------------------------- sound/soc/codecs/ssm2602.h | 4 +- sound/soc/codecs/uda1380.c | 205 +++++++++++------------------------------ sound/soc/codecs/uda1380.h | 4 +- 8 files changed, 190 insertions(+), 452 deletions(-)
diff --git a/sound/soc/codecs/jz4740.c b/sound/soc/codecs/jz4740.c index 66557de..f3bbf8c 100644 --- a/sound/soc/codecs/jz4740.c +++ b/sound/soc/codecs/jz4740.c @@ -74,29 +74,22 @@ static const uint32_t jz4740_codec_regs[] = { struct jz4740_codec { void __iomem *base; struct resource *mem; - - uint32_t reg_cache[2]; - struct snd_soc_codec codec; };
-static inline struct jz4740_codec *codec_to_jz4740(struct snd_soc_codec *codec) -{ - return container_of(codec, struct jz4740_codec, codec); -} - static unsigned int jz4740_codec_read(struct snd_soc_codec *codec, unsigned int reg) { - struct jz4740_codec *jz4740_codec = codec_to_jz4740(codec); + struct jz4740_codec *jz4740_codec = snd_soc_codec_get_drvdata(codec); return readl(jz4740_codec->base + (reg << 2)); }
static int jz4740_codec_write(struct snd_soc_codec *codec, unsigned int reg, unsigned int val) { - struct jz4740_codec *jz4740_codec = codec_to_jz4740(codec); + struct jz4740_codec *jz4740_codec = snd_soc_codec_get_drvdata(codec); + u32 *cache = codec->reg_cache;
- jz4740_codec->reg_cache[reg] = val; + cache[reg] = val; writel(val, jz4740_codec->base + (reg << 2));
return 0; @@ -172,8 +165,7 @@ static int jz4740_codec_hw_params(struct snd_pcm_substream *substream, { uint32_t val; 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;
switch (params_rate(params)) { case 8000: @@ -219,7 +211,7 @@ static struct snd_soc_dai_ops jz4740_codec_dai_ops = { .hw_params = jz4740_codec_hw_params, };
-struct snd_soc_dai jz4740_codec_dai = { +struct snd_soc_dai_driver jz4740_codec_dai = { .name = "jz4740", .playback = { .stream_name = "Playback", @@ -302,23 +294,10 @@ static int jz4740_codec_set_bias_level(struct snd_soc_codec *codec, return 0; }
-static struct snd_soc_codec *jz4740_codec_codec; - -static int jz4740_codec_dev_probe(struct platform_device *pdev) +static int jz4740_codec_dev_probe(struct snd_soc_codec *codec) { - int ret; - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = jz4740_codec_codec; - - BUG_ON(!codec); - - socdev->card->codec = codec; - - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret) { - dev_err(&pdev->dev, "Failed to create pcms: %d\n", ret); - return ret; - } + snd_soc_update_bits(codec, JZ4740_REG_CODEC_1, + JZ4740_CODEC_1_SW2_ENABLE, JZ4740_CODEC_1_SW2_ENABLE);
snd_soc_add_controls(codec, jz4740_codec_controls, ARRAY_SIZE(jz4740_codec_controls)); @@ -331,34 +310,27 @@ static int jz4740_codec_dev_probe(struct platform_device *pdev)
snd_soc_dapm_new_widgets(codec);
+ jz4740_codec_set_bias_level(codec, SND_SOC_BIAS_STANDBY); + return 0; }
-static int jz4740_codec_dev_remove(struct platform_device *pdev) +static int jz4740_codec_dev_remove(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - - snd_soc_free_pcms(socdev); - snd_soc_dapm_free(socdev); + jz4740_codec_set_bias_level(codec, SND_SOC_BIAS_OFF);
return 0; }
#ifdef CONFIG_PM_SLEEP
-static int jz4740_codec_suspend(struct platform_device *pdev, pm_message_t state) +static int jz4740_codec_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; - return jz4740_codec_set_bias_level(codec, SND_SOC_BIAS_OFF); }
-static int jz4740_codec_resume(struct platform_device *pdev) +static int jz4740_codec_resume(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - return jz4740_codec_set_bias_level(codec, SND_SOC_BIAS_STANDBY); }
@@ -367,11 +339,19 @@ static int jz4740_codec_resume(struct platform_device *pdev) #define jz4740_codec_resume NULL #endif
-struct snd_soc_codec_device soc_codec_dev_jz4740_codec = { +struct snd_soc_codec_driver soc_codec_dev_jz4740_codec = { + .name = "jz4740", + .owner = THIS_MODULE, .probe = jz4740_codec_dev_probe, .remove = jz4740_codec_dev_remove, .suspend = jz4740_codec_suspend, .resume = jz4740_codec_resume, + .read = jz4740_codec_read, + .write = jz4740_codec_write, + .set_bias_level = jz4740_codec_set_bias_level, + .reg_cache_default = jz4740_codec_regs, + .reg_word_size = sizeof(u32), + .reg_cache_size = 2, }; EXPORT_SYMBOL_GPL(soc_codec_dev_jz4740_codec);
@@ -379,7 +359,6 @@ static int __devinit jz4740_codec_probe(struct platform_device *pdev) { int ret; struct jz4740_codec *jz4740_codec; - struct snd_soc_codec *codec; struct resource *mem;
jz4740_codec = kzalloc(sizeof(*jz4740_codec), GFP_KERNEL); @@ -408,55 +387,17 @@ static int __devinit jz4740_codec_probe(struct platform_device *pdev) } jz4740_codec->mem = mem;
- jz4740_codec_dai.dev = &pdev->dev; - - codec = &jz4740_codec->codec; - - codec->dev = &pdev->dev; - codec->name = "jz4740"; - codec->owner = THIS_MODULE; - - codec->read = jz4740_codec_read; - codec->write = jz4740_codec_write; - codec->set_bias_level = jz4740_codec_set_bias_level; - codec->bias_level = SND_SOC_BIAS_OFF; - - codec->dai = &jz4740_codec_dai; - codec->num_dai = 1; - - codec->reg_cache = jz4740_codec->reg_cache; - codec->reg_cache_size = 2; - memcpy(codec->reg_cache, jz4740_codec_regs, sizeof(jz4740_codec_regs)); - - mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - jz4740_codec_codec = codec; - - snd_soc_update_bits(codec, JZ4740_REG_CODEC_1, - JZ4740_CODEC_1_SW2_ENABLE, JZ4740_CODEC_1_SW2_ENABLE); - platform_set_drvdata(pdev, jz4740_codec);
- ret = snd_soc_register_codec(codec); + ret = snd_soc_register_codec(&pdev->dev, pdev->id, + &soc_codec_dev_jz4740_codec, &jz4740_codec_dai, 1); if (ret) { dev_err(&pdev->dev, "Failed to register codec\n"); goto err_iounmap; }
- ret = snd_soc_register_dai(&jz4740_codec_dai); - if (ret) { - dev_err(&pdev->dev, "Failed to register codec dai\n"); - goto err_unregister_codec; - } - - jz4740_codec_set_bias_level(codec, SND_SOC_BIAS_STANDBY); - return 0;
-err_unregister_codec: - snd_soc_unregister_codec(codec); err_iounmap: iounmap(jz4740_codec->base); err_release_mem_region: @@ -472,8 +413,7 @@ static int __devexit jz4740_codec_remove(struct platform_device *pdev) struct jz4740_codec *jz4740_codec = platform_get_drvdata(pdev); struct resource *mem = jz4740_codec->mem;
- snd_soc_unregister_dai(&jz4740_codec_dai); - snd_soc_unregister_codec(&jz4740_codec->codec); + snd_soc_unregister_codec(&pdev->dev, pdev->id);
iounmap(jz4740_codec->base); release_mem_region(mem->start, resource_size(mem)); diff --git a/sound/soc/codecs/jz4740.h b/sound/soc/codecs/jz4740.h index b5a0691..d4b5d73 100644 --- a/sound/soc/codecs/jz4740.h +++ b/sound/soc/codecs/jz4740.h @@ -14,7 +14,7 @@ #ifndef __SND_SOC_CODECS_JZ4740_CODEC_H__ #define __SND_SOC_CODECS_JZ4740_CODEC_H__
-extern struct snd_soc_dai jz4740_codec_dai; -extern struct snd_soc_codec_device soc_codec_dev_jz4740_codec; +extern struct snd_soc_dai_driver jz4740_codec_dai; +extern struct snd_soc_codec_driver soc_codec_dev_jz4740_codec;
#endif diff --git a/sound/soc/codecs/pcm3008.c b/sound/soc/codecs/pcm3008.c index 5a5f187..23594c6 100644 --- a/sound/soc/codecs/pcm3008.c +++ b/sound/soc/codecs/pcm3008.c @@ -32,7 +32,7 @@ #define PCM3008_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \ SNDRV_PCM_RATE_48000)
-struct snd_soc_dai pcm3008_dai = { +struct snd_soc_dai_driver pcm3008_dai = { .name = "PCM3008 HiFi", .playback = { .stream_name = "PCM3008 Playback", @@ -59,38 +59,13 @@ static void pcm3008_gpio_free(struct pcm3008_setup_data *setup) gpio_free(setup->pdda_pin); }
-static int pcm3008_soc_probe(struct platform_device *pdev) +static int pcm3008_soc_probe(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - struct pcm3008_setup_data *setup = socdev->codec_data; + struct pcm3008_setup_data *setup = codec->dev->platform_data; int ret = 0;
printk(KERN_INFO "PCM3008 SoC Audio Codec %s\n", PCM3008_VERSION);
- socdev->card->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); - if (!socdev->card->codec) - return -ENOMEM; - - codec = socdev->card->codec; - mutex_init(&codec->mutex); - - codec->name = "PCM3008"; - codec->owner = THIS_MODULE; - codec->dai = &pcm3008_dai; - codec->num_dai = 1; - codec->write = NULL; - codec->read = NULL; - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - /* Register PCMs. */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret < 0) { - printk(KERN_ERR "pcm3008: failed to create pcms\n"); - goto pcm_err; - } - /* DEM1 DEM0 DE-EMPHASIS_MODE * Low Low De-emphasis 44.1 kHz ON * Low High De-emphasis OFF @@ -130,33 +105,22 @@ static int pcm3008_soc_probe(struct platform_device *pdev)
gpio_err: pcm3008_gpio_free(setup); -pcm_err: - kfree(socdev->card->codec);
return ret; }
-static int pcm3008_soc_remove(struct platform_device *pdev) +static int pcm3008_soc_remove(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - struct pcm3008_setup_data *setup = socdev->codec_data; - - if (!codec) - return 0; + struct pcm3008_setup_data *setup = codec->dev->platform_data;
pcm3008_gpio_free(setup); - snd_soc_free_pcms(socdev); - kfree(socdev->card->codec); - return 0; }
#ifdef CONFIG_PM -static int pcm3008_soc_suspend(struct platform_device *pdev, pm_message_t msg) +static int pcm3008_soc_suspend(struct snd_soc_codec *codec, pm_message_t msg) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct pcm3008_setup_data *setup = socdev->codec_data; + struct pcm3008_setup_data *setup = codec->dev->platform_data;
gpio_set_value(setup->pdad_pin, 0); gpio_set_value(setup->pdda_pin, 0); @@ -164,10 +128,9 @@ static int pcm3008_soc_suspend(struct platform_device *pdev, pm_message_t msg) return 0; }
-static int pcm3008_soc_resume(struct platform_device *pdev) +static int pcm3008_soc_resume(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct pcm3008_setup_data *setup = socdev->codec_data; + struct pcm3008_setup_data *setup = codec->dev->platform_data;
gpio_set_value(setup->pdad_pin, 1); gpio_set_value(setup->pdda_pin, 1); @@ -179,7 +142,9 @@ static int pcm3008_soc_resume(struct platform_device *pdev) #define pcm3008_soc_resume NULL #endif
-struct snd_soc_codec_device soc_codec_dev_pcm3008 = { +struct snd_soc_codec_driver soc_codec_dev_pcm3008 = { + .name = "PCM3008", + .owner = THIS_MODULE, .probe = pcm3008_soc_probe, .remove = pcm3008_soc_remove, .suspend = pcm3008_soc_suspend, @@ -187,15 +152,38 @@ struct snd_soc_codec_device soc_codec_dev_pcm3008 = { }; EXPORT_SYMBOL_GPL(soc_codec_dev_pcm3008);
-static int __init pcm3008_init(void) +static int __devinit pcm3008_codec_probe(struct platform_device *pdev) +{ + return snd_soc_register_codec(&pdev->dev, pdev->id, + &soc_codec_dev_pcm3008, &pcm3008_dai, 1); +} + +static int __devexit pcm3008_codec_remove(struct platform_device *pdev) +{ + snd_soc_unregister_codec(&pdev->dev, pdev->id); + return 0; +} + +MODULE_ALIAS("platform:pcm3008_codec_audio"); + +static struct platform_driver pcm3008_codec_driver = { + .probe = pcm3008_codec_probe, + .remove = __devexit_p(pcm3008_codec_remove), + .driver = { + .name = "pcm3008_codec_audio", + .owner = THIS_MODULE, + }, +}; + +static int __init pcm3008_modinit(void) { - return snd_soc_register_dai(&pcm3008_dai); + return platform_driver_register(&pcm3008_codec_driver); } -module_init(pcm3008_init); +module_init(pcm3008_modinit);
static void __exit pcm3008_exit(void) { - snd_soc_unregister_dai(&pcm3008_dai); + platform_driver_unregister(&pcm3008_codec_driver); } module_exit(pcm3008_exit);
diff --git a/sound/soc/codecs/pcm3008.h b/sound/soc/codecs/pcm3008.h index d04e87d..d1fe0b5 100644 --- a/sound/soc/codecs/pcm3008.h +++ b/sound/soc/codecs/pcm3008.h @@ -19,7 +19,7 @@ struct pcm3008_setup_data { unsigned pdda_pin; };
-extern struct snd_soc_codec_device soc_codec_dev_pcm3008; -extern struct snd_soc_dai pcm3008_dai; +extern struct snd_soc_codec_driver soc_codec_dev_pcm3008; +extern struct snd_soc_dai_driver pcm3008_dai;
#endif diff --git a/sound/soc/codecs/ssm2602.c b/sound/soc/codecs/ssm2602.c index b47ed4f..695413b 100644 --- a/sound/soc/codecs/ssm2602.c +++ b/sound/soc/codecs/ssm2602.c @@ -45,11 +45,11 @@
#define SSM2602_VERSION "0.1"
-struct snd_soc_codec_device soc_codec_dev_ssm2602; - /* codec private data */ struct ssm2602_priv { unsigned int sysclk; + enum snd_soc_control_type control_type; + void *control_data; struct snd_pcm_substream *master_substream; struct snd_pcm_substream *slave_substream; }; @@ -276,8 +276,7 @@ static int ssm2602_hw_params(struct snd_pcm_substream *substream, { u16 srate; 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 ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); struct i2c_client *i2c = codec->control_data; u16 iface = ssm2602_read_reg_cache(codec, SSM2602_IFACE) & 0xfff3; @@ -321,8 +320,7 @@ static int ssm2602_startup(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 ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); struct i2c_client *i2c = codec->control_data; struct snd_pcm_runtime *master_runtime; @@ -360,8 +358,7 @@ static int ssm2602_pcm_prepare(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; /* set active */ ssm2602_write(codec, SSM2602_ACTIVE, ACTIVE_ACTIVATE_CODEC);
@@ -372,8 +369,7 @@ static void ssm2602_shutdown(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 ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
/* deactivate */ @@ -518,7 +514,7 @@ static struct snd_soc_dai_ops ssm2602_dai_ops = { .set_fmt = ssm2602_set_dai_fmt, };
-struct snd_soc_dai ssm2602_dai = { +struct snd_soc_dai_driver ssm2602_dai = { .name = "SSM2602", .playback = { .stream_name = "Playback", @@ -536,19 +532,14 @@ struct snd_soc_dai ssm2602_dai = { }; EXPORT_SYMBOL_GPL(ssm2602_dai);
-static int ssm2602_suspend(struct platform_device *pdev, pm_message_t state) +static int ssm2602_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; - ssm2602_set_bias_level(codec, SND_SOC_BIAS_OFF); return 0; }
-static int ssm2602_resume(struct platform_device *pdev) +static int ssm2602_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; @@ -563,36 +554,18 @@ static int ssm2602_resume(struct platform_device *pdev) return 0; }
-/* - * initialise the ssm2602 driver - * register the mixer and dsp interfaces with the kernel - */ -static int ssm2602_init(struct snd_soc_device *socdev) +static int ssm2602_probe(struct snd_soc_codec *codec) { - struct snd_soc_codec *codec = socdev->card->codec; - int reg, ret = 0; - - codec->name = "SSM2602"; - codec->owner = THIS_MODULE; - codec->read = ssm2602_read_reg_cache; - codec->write = ssm2602_write; - codec->set_bias_level = ssm2602_set_bias_level; - codec->dai = &ssm2602_dai; - codec->num_dai = 1; - codec->reg_cache_size = sizeof(ssm2602_reg); - codec->reg_cache = kmemdup(ssm2602_reg, sizeof(ssm2602_reg), - GFP_KERNEL); - if (codec->reg_cache == NULL) - return -ENOMEM; + struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); + int ret = 0, reg; + + pr_info("ssm2602 Audio Codec %s", SSM2602_VERSION); + + codec->bias_level = SND_SOC_BIAS_OFF, + codec->control_data = ssm2602->control_data;
ssm2602_reset(codec);
- /* register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret < 0) { - pr_err("ssm2602: failed to create pcms\n"); - goto pcm_err; - } /*power on device*/ ssm2602_write(codec, SSM2602_ACTIVE, 0); /* set the update bits */ @@ -614,13 +587,30 @@ static int ssm2602_init(struct snd_soc_device *socdev) ssm2602_add_widgets(codec);
return ret; +}
-pcm_err: - kfree(codec->reg_cache); - return ret; +/* remove everything here */ +static int ssm2602_remove(struct snd_soc_codec *codec) +{ + ssm2602_set_bias_level(codec, SND_SOC_BIAS_OFF); + return 0; }
-static struct snd_soc_device *ssm2602_socdev; +struct snd_soc_codec_driver soc_codec_dev_ssm2602 = { + .name = "SSM2602", + .owner = THIS_MODULE, + .probe = ssm2602_probe, + .remove = ssm2602_remove, + .suspend = ssm2602_suspend, + .resume = ssm2602_resume, + .read = ssm2602_read_reg_cache, + .write = ssm2602_write, + .set_bias_level = ssm2602_set_bias_level, + .reg_cache_size = sizeof(ssm2602_reg), + .reg_word_size = sizeof(u16), + .reg_cache_default = ssm2602_reg, +}; +EXPORT_SYMBOL_GPL(soc_codec_dev_ssm2602);
#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) /* @@ -632,24 +622,28 @@ static struct snd_soc_device *ssm2602_socdev; static int ssm2602_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { - struct snd_soc_device *socdev = ssm2602_socdev; - struct snd_soc_codec *codec = socdev->card->codec; + struct ssm2602_priv *ssm2602; int ret;
- i2c_set_clientdata(i2c, codec); - codec->control_data = i2c; + ssm2602 = kzalloc(sizeof(struct ssm2602_priv), GFP_KERNEL); + if (ssm2602 == NULL) + return -ENOMEM; + + i2c_set_clientdata(i2c, ssm2602); + ssm2602->control_data = i2c; + ssm2602->control_type = SND_SOC_I2C;
- ret = ssm2602_init(socdev); + ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &soc_codec_dev_ssm2602, &ssm2602_dai, 1); if (ret < 0) - pr_err("failed to initialise SSM2602\n"); - + kfree(ssm2602); return ret; }
static int ssm2602_i2c_remove(struct i2c_client *client) { - struct snd_soc_codec *codec = i2c_get_clientdata(client); - kfree(codec->reg_cache); + snd_soc_unregister_codec(&client->dev, client->addr); + kfree(i2c_get_clientdata(client)); return 0; }
@@ -658,6 +652,7 @@ static const struct i2c_device_id ssm2602_i2c_id[] = { { } }; MODULE_DEVICE_TABLE(i2c, ssm2602_i2c_id); + /* corgi i2c codec control layer */ static struct i2c_driver ssm2602_i2c_driver = { .driver = { @@ -668,120 +663,28 @@ static struct i2c_driver ssm2602_i2c_driver = { .remove = ssm2602_i2c_remove, .id_table = ssm2602_i2c_id, }; - -static int ssm2602_add_i2c_device(struct platform_device *pdev, - const struct ssm2602_setup_data *setup) -{ - struct i2c_board_info info; - struct i2c_adapter *adapter; - struct i2c_client *client; - int ret; - - ret = i2c_add_driver(&ssm2602_i2c_driver); - if (ret != 0) { - dev_err(&pdev->dev, "can't add i2c driver\n"); - return ret; - } - memset(&info, 0, sizeof(struct i2c_board_info)); - info.addr = setup->i2c_address; - strlcpy(info.type, "ssm2602", I2C_NAME_SIZE); - adapter = i2c_get_adapter(setup->i2c_bus); - if (!adapter) { - dev_err(&pdev->dev, "can't get i2c adapter %d\n", - setup->i2c_bus); - goto err_driver; - } - client = i2c_new_device(adapter, &info); - i2c_put_adapter(adapter); - if (!client) { - dev_err(&pdev->dev, "can't add i2c device at 0x%x\n", - (unsigned int)info.addr); - goto err_driver; - } - return 0; -err_driver: - i2c_del_driver(&ssm2602_i2c_driver); - return -ENODEV; -} #endif
-static int ssm2602_probe(struct platform_device *pdev) + +static int __init ssm2602_modinit(void) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct ssm2602_setup_data *setup; - struct snd_soc_codec *codec; - struct ssm2602_priv *ssm2602; int ret = 0; - - pr_info("ssm2602 Audio Codec %s", SSM2602_VERSION); - - setup = socdev->codec_data; - codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); - if (codec == NULL) - return -ENOMEM; - - ssm2602 = kzalloc(sizeof(struct ssm2602_priv), GFP_KERNEL); - if (ssm2602 == NULL) { - kfree(codec); - return -ENOMEM; - } - - snd_soc_codec_set_drvdata(codec, ssm2602); - socdev->card->codec = codec; - mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - ssm2602_socdev = socdev; #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) - if (setup->i2c_address) { - codec->hw_write = (hw_write_t)i2c_master_send; - ret = ssm2602_add_i2c_device(pdev, setup); + ret = i2c_add_driver(&ssm2602_i2c_driver); + if (ret != 0) { + printk(KERN_ERR "Failed to register SSM2602 I2C driver: %d\n", + ret); } -#else - /* other interfaces */ #endif return ret; } +module_init(ssm2602_modinit);
-/* remove everything here */ -static int ssm2602_remove(struct platform_device *pdev) +static void __exit ssm2602_exit(void) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - - if (codec->control_data) - ssm2602_set_bias_level(codec, SND_SOC_BIAS_OFF); - - snd_soc_free_pcms(socdev); - snd_soc_dapm_free(socdev); #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) - i2c_unregister_device(codec->control_data); i2c_del_driver(&ssm2602_i2c_driver); #endif - kfree(snd_soc_codec_get_drvdata(codec)); - kfree(codec); - - return 0; -} - -struct snd_soc_codec_device soc_codec_dev_ssm2602 = { - .probe = ssm2602_probe, - .remove = ssm2602_remove, - .suspend = ssm2602_suspend, - .resume = ssm2602_resume, -}; -EXPORT_SYMBOL_GPL(soc_codec_dev_ssm2602); - -static int __init ssm2602_modinit(void) -{ - return snd_soc_register_dai(&ssm2602_dai); -} -module_init(ssm2602_modinit); - -static void __exit ssm2602_exit(void) -{ - snd_soc_unregister_dai(&ssm2602_dai); } module_exit(ssm2602_exit);
diff --git a/sound/soc/codecs/ssm2602.h b/sound/soc/codecs/ssm2602.h index f344e6d..ea10f14 100644 --- a/sound/soc/codecs/ssm2602.h +++ b/sound/soc/codecs/ssm2602.h @@ -124,7 +124,7 @@ struct ssm2602_setup_data { unsigned short i2c_address; };
-extern struct snd_soc_dai ssm2602_dai; -extern struct snd_soc_codec_device soc_codec_dev_ssm2602; +extern struct snd_soc_dai_driver ssm2602_dai; +extern struct snd_soc_codec_driver soc_codec_dev_ssm2602;
#endif diff --git a/sound/soc/codecs/uda1380.c b/sound/soc/codecs/uda1380.c index 2f925a2..f901164 100644 --- a/sound/soc/codecs/uda1380.c +++ b/sound/soc/codecs/uda1380.c @@ -33,11 +33,9 @@
#include "uda1380.h"
-static struct snd_soc_codec *uda1380_codec; - /* codec private data */ struct uda1380_priv { - struct snd_soc_codec codec; + struct snd_soc_codec *codec; u16 reg_cache[UDA1380_CACHEREGNUM]; unsigned int dac_clk; struct work_struct work; @@ -135,6 +133,8 @@ static int uda1380_write(struct snd_soc_codec *codec, unsigned int reg,
static void uda1380_flush_work(struct work_struct *work) { + struct uda1380_priv *uda1380 = container_of(work, struct uda1380_priv, work); + struct snd_soc_codec *uda1380_codec = uda1380->codec; int bit, reg;
for_each_set_bit(bit, &uda1380_cache_dirty, UDA1380_CACHEREGNUM - 0x10) { @@ -145,6 +145,7 @@ static void uda1380_flush_work(struct work_struct *work) uda1380_read_reg_cache(uda1380_codec, reg)); clear_bit(bit, &uda1380_cache_dirty); } + }
/* declarations of ALSA reg_elem_REAL controls */ @@ -474,8 +475,7 @@ static int uda1380_trigger(struct snd_pcm_substream *substream, int cmd, 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 uda1380_priv *uda1380 = snd_soc_codec_get_drvdata(codec); int mixer = uda1380_read_reg_cache(codec, UDA1380_MIXER);
@@ -501,8 +501,7 @@ static int uda1380_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; u16 clk = uda1380_read_reg_cache(codec, UDA1380_CLK);
/* set WSPLL power and divider if running from this clock */ @@ -540,8 +539,7 @@ static void uda1380_pcm_shutdown(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; u16 clk = uda1380_read_reg_cache(codec, UDA1380_CLK);
/* shut down WSPLL power if running from this clock */ @@ -604,7 +602,7 @@ static struct snd_soc_dai_ops uda1380_dai_ops_capture = { .set_fmt = uda1380_set_dai_fmt_capture, };
-struct snd_soc_dai uda1380_dai[] = { +struct snd_soc_dai_driver uda1380_dai[] = { { .name = "UDA1380", .playback = { @@ -646,19 +644,14 @@ struct snd_soc_dai uda1380_dai[] = { }; EXPORT_SYMBOL_GPL(uda1380_dai);
-static int uda1380_suspend(struct platform_device *pdev, pm_message_t state) +static int uda1380_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; - uda1380_set_bias_level(codec, SND_SOC_BIAS_OFF); return 0; }
-static int uda1380_resume(struct platform_device *pdev) +static int uda1380_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; @@ -673,91 +666,20 @@ static int uda1380_resume(struct platform_device *pdev) return 0; }
-static int uda1380_probe(struct platform_device *pdev) +static int uda1380_probe(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - struct uda1380_platform_data *pdata; - int ret = 0; - - if (uda1380_codec == NULL) { - dev_err(&pdev->dev, "Codec device not registered\n"); - return -ENODEV; - } - - socdev->card->codec = uda1380_codec; - codec = uda1380_codec; - pdata = codec->dev->platform_data; - - /* 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; - } - - /* power on device */ - uda1380_set_bias_level(codec, SND_SOC_BIAS_STANDBY); - /* set clock input */ - switch (pdata->dac_clk) { - case UDA1380_DAC_CLK_SYSCLK: - uda1380_write(codec, UDA1380_CLK, 0); - break; - case UDA1380_DAC_CLK_WSPLL: - uda1380_write(codec, UDA1380_CLK, R00_DAC_CLK); - break; - } - - snd_soc_add_controls(codec, uda1380_snd_controls, - ARRAY_SIZE(uda1380_snd_controls)); - uda1380_add_widgets(codec); - - return ret; - -pcm_err: - return ret; -} - -/* power down chip */ -static int uda1380_remove(struct platform_device *pdev) -{ - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - - if (codec->control_data) - uda1380_set_bias_level(codec, SND_SOC_BIAS_OFF); - - snd_soc_free_pcms(socdev); - snd_soc_dapm_free(socdev); - - return 0; -} - -struct snd_soc_codec_device soc_codec_dev_uda1380 = { - .probe = uda1380_probe, - .remove = uda1380_remove, - .suspend = uda1380_suspend, - .resume = uda1380_resume, -}; -EXPORT_SYMBOL_GPL(soc_codec_dev_uda1380); - -static int uda1380_register(struct uda1380_priv *uda1380) -{ - int ret, i; - struct snd_soc_codec *codec = &uda1380->codec; - struct uda1380_platform_data *pdata = codec->dev->platform_data; + struct uda1380_platform_data *pdata =codec->dev->platform_data; + struct uda1380_priv *uda1380 = snd_soc_codec_get_drvdata(codec); + int ret;
- if (uda1380_codec) { - dev_err(codec->dev, "Another UDA1380 is registered\n"); - return -EINVAL; - } + codec->hw_write = (hw_write_t)i2c_master_send;
if (!pdata || !pdata->gpio_power || !pdata->gpio_reset) return -EINVAL;
ret = gpio_request(pdata->gpio_power, "uda1380 power"); if (ret) - goto err_out; + return ret; ret = gpio_request(pdata->gpio_reset, "uda1380 reset"); if (ret) goto err_gpio; @@ -769,25 +691,6 @@ static int uda1380_register(struct uda1380_priv *uda1380) udelay(5); gpio_set_value(pdata->gpio_reset, 0);
- mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - snd_soc_codec_set_drvdata(codec, uda1380); - codec->name = "UDA1380"; - codec->owner = THIS_MODULE; - codec->read = uda1380_read_reg_cache; - codec->write = uda1380_write; - codec->bias_level = SND_SOC_BIAS_OFF; - codec->set_bias_level = uda1380_set_bias_level; - codec->dai = uda1380_dai; - codec->num_dai = ARRAY_SIZE(uda1380_dai); - codec->reg_cache_size = ARRAY_SIZE(uda1380_reg); - codec->reg_cache = &uda1380->reg_cache; - codec->reg_cache_step = 1; - - memcpy(codec->reg_cache, uda1380_reg, sizeof(uda1380_reg)); - ret = uda1380_reset(codec); if (ret < 0) { dev_err(codec->dev, "Failed to issue reset\n"); @@ -796,83 +699,87 @@ static int uda1380_register(struct uda1380_priv *uda1380)
INIT_WORK(&uda1380->work, uda1380_flush_work);
- for (i = 0; i < ARRAY_SIZE(uda1380_dai); i++) - uda1380_dai[i].dev = codec->dev; - - uda1380_codec = codec; - - ret = snd_soc_register_codec(codec); - if (ret != 0) { - dev_err(codec->dev, "Failed to register codec: %d\n", ret); - goto err_reset; + /* power on device */ + uda1380_set_bias_level(codec, SND_SOC_BIAS_STANDBY); + /* set clock input */ + switch (pdata->dac_clk) { + case UDA1380_DAC_CLK_SYSCLK: + uda1380_write(codec, UDA1380_CLK, 0); + break; + case UDA1380_DAC_CLK_WSPLL: + uda1380_write(codec, UDA1380_CLK, R00_DAC_CLK); + break; }
- ret = snd_soc_register_dais(uda1380_dai, ARRAY_SIZE(uda1380_dai)); - if (ret != 0) { - dev_err(codec->dev, "Failed to register DAIs: %d\n", ret); - goto err_dai; - } + snd_soc_add_controls(codec, uda1380_snd_controls, + ARRAY_SIZE(uda1380_snd_controls)); + uda1380_add_widgets(codec);
return 0;
-err_dai: - snd_soc_unregister_codec(codec); err_reset: gpio_set_value(pdata->gpio_power, 0); gpio_free(pdata->gpio_reset); err_gpio: gpio_free(pdata->gpio_power); -err_out: return ret; }
-static void uda1380_unregister(struct uda1380_priv *uda1380) +/* power down chip */ +static int uda1380_remove(struct snd_soc_codec *codec) { - struct snd_soc_codec *codec = &uda1380->codec; - struct uda1380_platform_data *pdata = codec->dev->platform_data; + struct uda1380_platform_data *pdata =codec->dev->platform_data;
- snd_soc_unregister_dais(uda1380_dai, ARRAY_SIZE(uda1380_dai)); - snd_soc_unregister_codec(&uda1380->codec); + uda1380_set_bias_level(codec, SND_SOC_BIAS_OFF);
gpio_set_value(pdata->gpio_power, 0); gpio_free(pdata->gpio_reset); gpio_free(pdata->gpio_power);
- kfree(uda1380); - uda1380_codec = NULL; + return 0; }
+struct snd_soc_codec_driver soc_codec_dev_uda1380 = { + .name = "UDA1380", + .owner = THIS_MODULE, + .probe = uda1380_probe, + .remove = uda1380_remove, + .suspend = uda1380_suspend, + .resume = uda1380_resume, + .read = uda1380_read_reg_cache, + .write = uda1380_write, + .set_bias_level = uda1380_set_bias_level, + .reg_cache_size = ARRAY_SIZE(uda1380_reg), + .reg_word_size = sizeof(u16), + .reg_cache_default = uda1380_reg, + .reg_cache_step = 1, +}; +EXPORT_SYMBOL_GPL(soc_codec_dev_uda1380); + #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) static __devinit int uda1380_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct uda1380_priv *uda1380; - struct snd_soc_codec *codec; int ret;
uda1380 = kzalloc(sizeof(struct uda1380_priv), GFP_KERNEL); if (uda1380 == NULL) return -ENOMEM;
- codec = &uda1380->codec; - codec->hw_write = (hw_write_t)i2c_master_send; - i2c_set_clientdata(i2c, uda1380); - codec->control_data = i2c; - - codec->dev = &i2c->dev;
- ret = uda1380_register(uda1380); - if (ret != 0) + ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &soc_codec_dev_uda1380, uda1380_dai, ARRAY_SIZE(uda1380_dai)); + if (ret < 0) kfree(uda1380); - return ret; }
static int __devexit uda1380_i2c_remove(struct i2c_client *i2c) { - struct uda1380_priv *uda1380 = i2c_get_clientdata(i2c); - uda1380_unregister(uda1380); + snd_soc_unregister_codec(&i2c->dev, i2c->addr); + kfree(i2c_get_clientdata(i2c)); return 0; }
diff --git a/sound/soc/codecs/uda1380.h b/sound/soc/codecs/uda1380.h index 9cefa8a..73158b9 100644 --- a/sound/soc/codecs/uda1380.h +++ b/sound/soc/codecs/uda1380.h @@ -76,7 +76,7 @@ #define UDA1380_DAI_PLAYBACK 1 /* playback DAI */ #define UDA1380_DAI_CAPTURE 2 /* capture DAI */
-extern struct snd_soc_dai uda1380_dai[3]; -extern struct snd_soc_codec_device soc_codec_dev_uda1380; +extern struct snd_soc_dai_driver uda1380_dai[3]; +extern struct snd_soc_codec_driver soc_codec_dev_uda1380;
#endif /* _UDA1380_H */
Move TI CODECs to multi-component
This patch changes the probe() and remove() of the CODEC drivers as follows:-
o Make CODEC driver a platform device (non MFD codecs only) o Moved all struct snd_soc_codec list, mutex, etc initialiasation to core. o Removed all static codec pointers (drivers now support > 1 codec dev) o snd_soc_register_pcms() now done by core. o snd_soc_register_dai() folded into snd_soc_register_codec(). o codec cache can now be malloc()ed by core.
Other required changes due to multi-component model :-
o tlv320aic3x: no more "setup_data" from ASoC machine drivers, platform data must be set in one place only. Moved platform defs out into platorm header.
Signed-off-by: Liam Girdwood lrg@slimlogic.co.uk --- include/sound/tlv320aic3x.h | 43 ++++++- sound/soc/codecs/tlv320aic23.c | 178 ++++++++---------------- sound/soc/codecs/tlv320aic23.h | 4 +- sound/soc/codecs/tlv320aic26.c | 177 ++++++++--------------- sound/soc/codecs/tlv320aic26.h | 4 +- sound/soc/codecs/tlv320aic3x.c | 276 +++++++++++++----------------------- sound/soc/codecs/tlv320aic3x.h | 44 +------ sound/soc/codecs/tlv320dac33.c | 304 +++++++++++++++------------------------- sound/soc/codecs/tlv320dac33.h | 4 +- sound/soc/codecs/twl4030.c | 193 +++++++------------------- sound/soc/codecs/twl4030.h | 4 +- sound/soc/codecs/twl6040.c | 170 ++++++---------------- sound/soc/codecs/twl6040.h | 4 +- 13 files changed, 486 insertions(+), 919 deletions(-)
diff --git a/include/sound/tlv320aic3x.h b/include/sound/tlv320aic3x.h index b1a5f34..99e0308 100644 --- a/include/sound/tlv320aic3x.h +++ b/include/sound/tlv320aic3x.h @@ -10,8 +10,49 @@ #ifndef __TLV320AIC3x_H__ #define __TLV320AIC3x_H__
+/* GPIO API */ +enum { + AIC3X_GPIO1_FUNC_DISABLED = 0, + AIC3X_GPIO1_FUNC_AUDIO_WORDCLK_ADC = 1, + AIC3X_GPIO1_FUNC_CLOCK_MUX = 2, + AIC3X_GPIO1_FUNC_CLOCK_MUX_DIV2 = 3, + AIC3X_GPIO1_FUNC_CLOCK_MUX_DIV4 = 4, + AIC3X_GPIO1_FUNC_CLOCK_MUX_DIV8 = 5, + AIC3X_GPIO1_FUNC_SHORT_CIRCUIT_IRQ = 6, + AIC3X_GPIO1_FUNC_AGC_NOISE_IRQ = 7, + AIC3X_GPIO1_FUNC_INPUT = 8, + AIC3X_GPIO1_FUNC_OUTPUT = 9, + AIC3X_GPIO1_FUNC_DIGITAL_MIC_MODCLK = 10, + AIC3X_GPIO1_FUNC_AUDIO_WORDCLK = 11, + AIC3X_GPIO1_FUNC_BUTTON_IRQ = 12, + AIC3X_GPIO1_FUNC_HEADSET_DETECT_IRQ = 13, + AIC3X_GPIO1_FUNC_HEADSET_DETECT_OR_BUTTON_IRQ = 14, + AIC3X_GPIO1_FUNC_ALL_IRQ = 16 +}; + +enum { + AIC3X_GPIO2_FUNC_DISABLED = 0, + AIC3X_GPIO2_FUNC_HEADSET_DETECT_IRQ = 2, + AIC3X_GPIO2_FUNC_INPUT = 3, + AIC3X_GPIO2_FUNC_OUTPUT = 4, + AIC3X_GPIO2_FUNC_DIGITAL_MIC_INPUT = 5, + AIC3X_GPIO2_FUNC_AUDIO_BITCLK = 8, + AIC3X_GPIO2_FUNC_HEADSET_DETECT_OR_BUTTON_IRQ = 9, + AIC3X_GPIO2_FUNC_ALL_IRQ = 10, + AIC3X_GPIO2_FUNC_SHORT_CIRCUIT_OR_AGC_IRQ = 11, + AIC3X_GPIO2_FUNC_HEADSET_OR_BUTTON_PRESS_OR_SHORT_CIRCUIT_IRQ = 12, + AIC3X_GPIO2_FUNC_SHORT_CIRCUIT_IRQ = 13, + AIC3X_GPIO2_FUNC_AGC_NOISE_IRQ = 14, + AIC3X_GPIO2_FUNC_BUTTON_PRESS_IRQ = 15 +}; + +struct aic3x_setup_data { + unsigned int gpio_func[2]; +}; + struct aic3x_pdata { int gpio_reset; /* < 0 if not used */ + struct aic3x_setup_data *setup; };
-#endif \ No newline at end of file +#endif diff --git a/sound/soc/codecs/tlv320aic23.c b/sound/soc/codecs/tlv320aic23.c index b0bae35..fbc95c5 100644 --- a/sound/soc/codecs/tlv320aic23.c +++ b/sound/soc/codecs/tlv320aic23.c @@ -240,7 +240,8 @@ static const struct snd_soc_dapm_route intercon[] = {
/* AIC23 driver data */ struct aic23 { - struct snd_soc_codec codec; + enum snd_soc_control_type control_type; + void *control_data; int mclk; int requested_adc; int requested_dac; @@ -404,11 +405,10 @@ static int tlv320aic23_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; u16 iface_reg; int ret; - struct aic23 *aic23 = container_of(codec, struct aic23, codec); + struct aic23 *aic23 = snd_soc_codec_get_drvdata(codec); u32 sample_rate_adc = aic23->requested_adc; u32 sample_rate_dac = aic23->requested_dac; u32 sample_rate = params_rate(params); @@ -452,8 +452,7 @@ static int tlv320aic23_pcm_prepare(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;
/* set active */ tlv320aic23_write(codec, TLV320AIC23_ACTIVE, 0x0001); @@ -465,9 +464,8 @@ static void tlv320aic23_shutdown(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 aic23 *aic23 = container_of(codec, struct aic23, codec); + struct snd_soc_codec *codec = rtd->codec; + struct aic23 *aic23 = snd_soc_codec_get_drvdata(codec);
/* deactivate */ if (!codec->active) { @@ -546,8 +544,7 @@ static int tlv320aic23_set_dai_fmt(struct snd_soc_dai *codec_dai, static int tlv320aic23_set_dai_sysclk(struct snd_soc_dai *codec_dai, int clk_id, unsigned int freq, int dir) { - struct snd_soc_codec *codec = codec_dai->codec; - struct aic23 *aic23 = container_of(codec, struct aic23, codec); + struct aic23 *aic23 = snd_soc_dai_get_drvdata(codec_dai); aic23->mclk = freq; return 0; } @@ -591,7 +588,7 @@ static struct snd_soc_dai_ops tlv320aic23_dai_ops = { .set_sysclk = tlv320aic23_set_dai_sysclk, };
-struct snd_soc_dai tlv320aic23_dai = { +struct snd_soc_dai_driver tlv320aic23_dai = { .name = "tlv320aic23", .playback = { .stream_name = "Playback", @@ -609,22 +606,17 @@ struct snd_soc_dai tlv320aic23_dai = { }; EXPORT_SYMBOL_GPL(tlv320aic23_dai);
-static int tlv320aic23_suspend(struct platform_device *pdev, +static int tlv320aic23_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; - tlv320aic23_write(codec, TLV320AIC23_ACTIVE, 0x0); tlv320aic23_set_bias_level(codec, SND_SOC_BIAS_OFF);
return 0; }
-static int tlv320aic23_resume(struct platform_device *pdev) +static int tlv320aic23_resume(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; u16 reg;
/* Sync reg_cache with the hardware */ @@ -638,39 +630,17 @@ static int tlv320aic23_resume(struct platform_device *pdev) return 0; }
-/* - * initialise the AIC23 driver - * register the mixer and dsp interfaces with the kernel - */ -static int tlv320aic23_init(struct snd_soc_device *socdev) +static int tlv320aic23_probe(struct snd_soc_codec *codec) { - struct snd_soc_codec *codec = socdev->card->codec; - int ret = 0; - u16 reg; + struct aic23 *aic23 = snd_soc_codec_get_drvdata(codec); + int reg;
- codec->name = "tlv320aic23"; - codec->owner = THIS_MODULE; - codec->read = tlv320aic23_read_reg_cache; - codec->write = tlv320aic23_write; - codec->set_bias_level = tlv320aic23_set_bias_level; - codec->dai = &tlv320aic23_dai; - codec->num_dai = 1; - codec->reg_cache_size = ARRAY_SIZE(tlv320aic23_reg); - codec->reg_cache = - kmemdup(tlv320aic23_reg, sizeof(tlv320aic23_reg), GFP_KERNEL); - if (codec->reg_cache == NULL) - return -ENOMEM; + printk(KERN_INFO "AIC23 Audio Codec %s\n", AIC23_VERSION); + codec->control_data = aic23->control_data;
/* Reset codec */ tlv320aic23_write(codec, TLV320AIC23_RESET, 0);
- /* register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret < 0) { - printk(KERN_ERR "tlv320aic23: failed to create pcms\n"); - goto pcm_err; - } - /* power on device */ tlv320aic23_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
@@ -706,13 +676,30 @@ static int tlv320aic23_init(struct snd_soc_device *socdev) ARRAY_SIZE(tlv320aic23_snd_controls)); tlv320aic23_add_widgets(codec);
- return ret; + return 0; +}
-pcm_err: - kfree(codec->reg_cache); - return ret; +static int tlv320aic23_remove(struct snd_soc_codec *codec) +{ + tlv320aic23_set_bias_level(codec, SND_SOC_BIAS_OFF); + return 0; } -static struct snd_soc_device *tlv320aic23_socdev; + +struct snd_soc_codec_driver soc_codec_dev_tlv320aic23 = { + .name = "tlv320aic23", + .owner = THIS_MODULE, + .reg_cache_size = ARRAY_SIZE(tlv320aic23_reg), + .reg_word_size = sizeof(u16), + .reg_cache_default = tlv320aic23_reg, + .probe = tlv320aic23_probe, + .remove = tlv320aic23_remove, + .suspend = tlv320aic23_suspend, + .resume = tlv320aic23_resume, + .read = tlv320aic23_read_reg_cache, + .write = tlv320aic23_write, + .set_bias_level = tlv320aic23_set_bias_level, +}; +EXPORT_SYMBOL_GPL(soc_codec_dev_tlv320aic23);
#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) /* @@ -722,31 +709,30 @@ static struct snd_soc_device *tlv320aic23_socdev; static int tlv320aic23_codec_probe(struct i2c_client *i2c, const struct i2c_device_id *i2c_id) { - struct snd_soc_device *socdev = tlv320aic23_socdev; - struct snd_soc_codec *codec = socdev->card->codec; + struct aic23 *aic23; int ret;
if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -EINVAL;
- i2c_set_clientdata(i2c, codec); - codec->control_data = i2c; + aic23 = kzalloc(sizeof(struct aic23), GFP_KERNEL); + if (aic23 == NULL) + return -ENOMEM;
- ret = tlv320aic23_init(socdev); - if (ret < 0) { - printk(KERN_ERR "tlv320aic23: failed to initialise AIC23\n"); - goto err; - } - return ret; + i2c_set_clientdata(i2c, aic23); + aic23->control_data = i2c; + aic23->control_type = SND_SOC_I2C;
-err: - kfree(codec); - kfree(i2c); + ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &soc_codec_dev_tlv320aic23, &tlv320aic23_dai, 1); + if (ret < 0) + kfree(aic23); return ret; } static int __exit tlv320aic23_i2c_remove(struct i2c_client *i2c) { - put_device(&i2c->dev); + snd_soc_unregister_codec(&i2c->dev, i2c->addr); + kfree(i2c_get_clientdata(i2c)); return 0; }
@@ -768,71 +754,25 @@ static struct i2c_driver tlv320aic23_i2c_driver = {
#endif
-static int tlv320aic23_probe(struct platform_device *pdev) +static int __init tlv320aic23_modinit(void) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - struct aic23 *aic23; - int ret = 0; - - printk(KERN_INFO "AIC23 Audio Codec %s\n", AIC23_VERSION); - - aic23 = kzalloc(sizeof(struct aic23), GFP_KERNEL); - if (aic23 == NULL) - return -ENOMEM; - codec = &aic23->codec; - socdev->card->codec = codec; - mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - tlv320aic23_socdev = socdev; + int ret; #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) - codec->hw_write = (hw_write_t) i2c_master_send; - codec->hw_read = NULL; ret = i2c_add_driver(&tlv320aic23_i2c_driver); - if (ret != 0) - printk(KERN_ERR "can't add i2c driver"); + if (ret != 0) { + printk(KERN_ERR "Failed to register TLV320AIC23 I2C driver: %d\n", + ret); + } #endif return ret; } +module_init(tlv320aic23_modinit);
-static int tlv320aic23_remove(struct platform_device *pdev) +static void __exit tlv320aic23_exit(void) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - struct aic23 *aic23 = container_of(codec, struct aic23, codec); - - if (codec->control_data) - tlv320aic23_set_bias_level(codec, SND_SOC_BIAS_OFF); - - snd_soc_free_pcms(socdev); - snd_soc_dapm_free(socdev); #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) i2c_del_driver(&tlv320aic23_i2c_driver); #endif - kfree(codec->reg_cache); - kfree(aic23); - - return 0; -} -struct snd_soc_codec_device soc_codec_dev_tlv320aic23 = { - .probe = tlv320aic23_probe, - .remove = tlv320aic23_remove, - .suspend = tlv320aic23_suspend, - .resume = tlv320aic23_resume, -}; -EXPORT_SYMBOL_GPL(soc_codec_dev_tlv320aic23); - -static int __init tlv320aic23_modinit(void) -{ - return snd_soc_register_dai(&tlv320aic23_dai); -} -module_init(tlv320aic23_modinit); - -static void __exit tlv320aic23_exit(void) -{ - snd_soc_unregister_dai(&tlv320aic23_dai); } module_exit(tlv320aic23_exit);
diff --git a/sound/soc/codecs/tlv320aic23.h b/sound/soc/codecs/tlv320aic23.h index 79d1faf..84ce2b3 100644 --- a/sound/soc/codecs/tlv320aic23.h +++ b/sound/soc/codecs/tlv320aic23.h @@ -116,7 +116,7 @@ #define TLV320AIC23_SIDETONE_12 0x080 #define TLV320AIC23_SIDETONE_18 0x0c0
-extern struct snd_soc_dai tlv320aic23_dai; -extern struct snd_soc_codec_device soc_codec_dev_tlv320aic23; +extern struct snd_soc_dai_driver tlv320aic23_dai; +extern struct snd_soc_codec_driver soc_codec_dev_tlv320aic23;
#endif /* _TLV320AIC23_H */ diff --git a/sound/soc/codecs/tlv320aic26.c b/sound/soc/codecs/tlv320aic26.c index f0e00fd..0852b16 100644 --- a/sound/soc/codecs/tlv320aic26.c +++ b/sound/soc/codecs/tlv320aic26.c @@ -130,8 +130,7 @@ static int aic26_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 aic26 *aic26 = snd_soc_codec_get_drvdata(codec); int fsref, divisor, wlen, pval, jval, dval, qval; u16 reg; @@ -278,7 +277,7 @@ static struct snd_soc_dai_ops aic26_dai_ops = { .set_fmt = aic26_set_fmt, };
-struct snd_soc_dai aic26_dai = { +struct snd_soc_dai_driver aic26_dai = { .name = "tlv320aic26", .playback = { .stream_name = "Playback", @@ -319,61 +318,6 @@ static const struct snd_kcontrol_new aic26_snd_controls[] = { };
/* --------------------------------------------------------------------- - * SoC CODEC portion of driver: probe and release routines - */ -static int aic26_probe(struct platform_device *pdev) -{ - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - struct aic26 *aic26; - int ret, err; - - dev_info(&pdev->dev, "Probing AIC26 SoC CODEC driver\n"); - dev_dbg(&pdev->dev, "socdev=%p\n", socdev); - dev_dbg(&pdev->dev, "codec_data=%p\n", socdev->codec_data); - - /* Fetch the relevant aic26 private data here (it's already been - * stored in the .codec pointer) */ - aic26 = socdev->codec_data; - if (aic26 == NULL) { - dev_err(&pdev->dev, "aic26: missing codec pointer\n"); - return -ENODEV; - } - codec = &aic26->codec; - socdev->card->codec = codec; - - dev_dbg(&pdev->dev, "Registering PCMs, dev=%p, socdev->dev=%p\n", - &pdev->dev, socdev->dev); - /* register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret < 0) { - dev_err(&pdev->dev, "aic26: failed to create pcms\n"); - return -ENODEV; - } - - /* register controls */ - dev_dbg(&pdev->dev, "Registering controls\n"); - err = snd_soc_add_controls(codec, aic26_snd_controls, - ARRAY_SIZE(aic26_snd_controls)); - WARN_ON(err < 0); - - return 0; -} - -static int aic26_remove(struct platform_device *pdev) -{ - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - snd_soc_free_pcms(socdev); - return 0; -} - -struct snd_soc_codec_device aic26_soc_codec_dev = { - .probe = aic26_probe, - .remove = aic26_remove, -}; -EXPORT_SYMBOL_GPL(aic26_soc_codec_dev); - -/* --------------------------------------------------------------------- * SPI device portion of driver: sysfs files for debugging */
@@ -409,89 +353,92 @@ static ssize_t aic26_keyclick_set(struct device *dev, static DEVICE_ATTR(keyclick, 0644, aic26_keyclick_show, aic26_keyclick_set);
/* --------------------------------------------------------------------- - * SPI device portion of driver: probe and release routines and SPI - * driver registration. + * SoC CODEC portion of driver: probe and release routines */ -static int aic26_spi_probe(struct spi_device *spi) +static int aic26_probe(struct snd_soc_codec *codec) { - struct aic26 *aic26; - int ret, i, reg; - - dev_dbg(&spi->dev, "probing tlv320aic26 spi device\n"); - - /* Allocate driver data */ - aic26 = kzalloc(sizeof *aic26, GFP_KERNEL); - if (!aic26) - return -ENOMEM; - - /* Initialize the driver data */ - aic26->spi = spi; - dev_set_drvdata(&spi->dev, aic26); + struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec); + int ret, err, i, reg;
- /* Setup what we can in the codec structure so that the register - * access functions will work as expected. More will be filled - * out when it is probed by the SoC CODEC part of this driver */ - snd_soc_codec_set_drvdata(&aic26->codec, aic26); - aic26->codec.name = "aic26"; - aic26->codec.owner = THIS_MODULE; - aic26->codec.dai = &aic26_dai; - aic26->codec.num_dai = 1; - aic26->codec.read = aic26_reg_read; - aic26->codec.write = aic26_reg_write; - aic26->master = 1; - mutex_init(&aic26->codec.mutex); - INIT_LIST_HEAD(&aic26->codec.dapm_widgets); - INIT_LIST_HEAD(&aic26->codec.dapm_paths); - aic26->codec.reg_cache_size = AIC26_NUM_REGS; - aic26->codec.reg_cache = aic26->reg_cache; - - aic26_dai.dev = &spi->dev; - ret = snd_soc_register_dai(&aic26_dai); - if (ret != 0) { - dev_err(&spi->dev, "Failed to register DAI: %d\n", ret); - kfree(aic26); - return ret; - } + dev_info(codec->dev, "Probing AIC26 SoC CODEC driver\n");
/* Reset the codec to power on defaults */ - aic26_reg_write(&aic26->codec, AIC26_REG_RESET, 0xBB00); + aic26_reg_write(codec, AIC26_REG_RESET, 0xBB00);
/* Power up CODEC */ - aic26_reg_write(&aic26->codec, AIC26_REG_POWER_CTRL, 0); + aic26_reg_write(codec, AIC26_REG_POWER_CTRL, 0);
/* Audio Control 3 (master mode, fsref rate) */ - reg = aic26_reg_read(&aic26->codec, AIC26_REG_AUDIO_CTRL3); + reg = aic26_reg_read(codec, AIC26_REG_AUDIO_CTRL3); reg &= ~0xf800; reg |= 0x0800; /* set master mode */ - aic26_reg_write(&aic26->codec, AIC26_REG_AUDIO_CTRL3, reg); + aic26_reg_write(codec, AIC26_REG_AUDIO_CTRL3, reg);
/* Fill register cache */ for (i = 0; i < ARRAY_SIZE(aic26->reg_cache); i++) - aic26_reg_read(&aic26->codec, i); + aic26_reg_read(codec, i);
/* Register the sysfs files for debugging */ /* Create SysFS files */ - ret = device_create_file(&spi->dev, &dev_attr_keyclick); + ret = device_create_file(codec->dev, &dev_attr_keyclick); if (ret) - dev_info(&spi->dev, "error creating sysfs files\n"); + dev_info(codec->dev, "error creating sysfs files\n");
-#if defined(CONFIG_SND_SOC_OF_SIMPLE) - /* Tell the of_soc helper about this codec */ - of_snd_soc_register_codec(&aic26_soc_codec_dev, aic26, &aic26_dai, - spi->dev.archdata.of_node); -#endif + /* register controls */ + dev_dbg(codec->dev, "Registering controls\n"); + err = snd_soc_add_controls(codec, aic26_snd_controls, + ARRAY_SIZE(aic26_snd_controls)); + WARN_ON(err < 0);
- dev_dbg(&spi->dev, "SPI device initialized\n"); return 0; }
-static int aic26_spi_remove(struct spi_device *spi) +struct snd_soc_codec_driver aic26_soc_codec_dev = { + .name = "aic26", + .owner = THIS_MODULE, + .probe = aic26_probe, + .read = aic26_reg_read, + .write = aic26_reg_write, + .reg_cache_size = AIC26_NUM_REGS, + .reg_word_size = sizeof(u16), +}; +EXPORT_SYMBOL_GPL(aic26_soc_codec_dev); + +/* --------------------------------------------------------------------- + * SPI device portion of driver: probe and release routines and SPI + * driver registration. + */ +static int aic26_spi_probe(struct spi_device *spi) { - struct aic26 *aic26 = dev_get_drvdata(&spi->dev); + struct aic26 *aic26; + int ret; + + dev_dbg(&spi->dev, "probing tlv320aic26 spi device\n"); + + /* Allocate driver data */ + aic26 = kzalloc(sizeof *aic26, GFP_KERNEL); + if (!aic26) + return -ENOMEM; + + /* Initialize the driver data */ + aic26->spi = spi; + dev_set_drvdata(&spi->dev, aic26); + aic26->master = 1; + + ret = snd_soc_register_codec(&spi->dev, spi->chip_select, + &aic26_soc_codec_dev, &aic26_dai, 1); + if (ret < 0) + kfree(aic26); + return ret;
- snd_soc_unregister_dai(&aic26_dai); - kfree(aic26); + dev_dbg(&spi->dev, "SPI device initialized\n"); + return 0; +}
+static int aic26_spi_remove(struct spi_device *spi) +{ + snd_soc_unregister_codec(&spi->dev, spi->chip_select); + kfree(spi_get_drvdata(spi)); return 0; }
diff --git a/sound/soc/codecs/tlv320aic26.h b/sound/soc/codecs/tlv320aic26.h index 786ba16..cdfee4c 100644 --- a/sound/soc/codecs/tlv320aic26.h +++ b/sound/soc/codecs/tlv320aic26.h @@ -90,7 +90,7 @@ enum aic26_wlen { AIC26_WLEN_32 = 3 << 10, };
-extern struct snd_soc_dai aic26_dai; -extern struct snd_soc_codec_device aic26_soc_codec_dev; +extern struct snd_soc_dai_driver aic26_dai; +extern struct snd_soc_codec_driver aic26_soc_codec_dev;
#endif /* _TLV320AIC16_H_ */ diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c index 71a6990..d2ed13e 100644 --- a/sound/soc/codecs/tlv320aic3x.c +++ b/sound/soc/codecs/tlv320aic3x.c @@ -63,8 +63,9 @@ static const char *aic3x_supply_names[AIC3X_NUM_SUPPLIES] = {
/* codec private data */ struct aic3x_priv { - struct snd_soc_codec codec; struct regulator_bulk_data supplies[AIC3X_NUM_SUPPLIES]; + enum snd_soc_control_type control_type; + void *control_data; unsigned int sysclk; int master; int gpio_reset; @@ -773,8 +774,7 @@ static int aic3x_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 aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec); int codec_clk = 0, bypass_pll = 0, fsref, last_clk = 0; u8 data, j, r, p, pll_q, pll_p = 1, pll_r = 1, pll_j = 1; @@ -1101,7 +1101,7 @@ static struct snd_soc_dai_ops aic3x_dai_ops = { .set_fmt = aic3x_set_dai_fmt, };
-struct snd_soc_dai aic3x_dai = { +struct snd_soc_dai_driver aic3x_dai = { .name = "tlv320aic3x", .playback = { .stream_name = "Playback", @@ -1119,20 +1119,15 @@ struct snd_soc_dai aic3x_dai = { }; EXPORT_SYMBOL_GPL(aic3x_dai);
-static int aic3x_suspend(struct platform_device *pdev, pm_message_t state) +static int aic3x_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; - aic3x_set_bias_level(codec, SND_SOC_BIAS_OFF);
return 0; }
-static int aic3x_resume(struct platform_device *pdev) +static int aic3x_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]; u8 *cache = codec->reg_cache; @@ -1157,22 +1152,6 @@ static int aic3x_init(struct snd_soc_codec *codec) { int reg;
- mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - codec->name = "tlv320aic3x"; - codec->owner = THIS_MODULE; - codec->read = aic3x_read_reg_cache; - codec->write = aic3x_write; - codec->set_bias_level = aic3x_set_bias_level; - codec->dai = &aic3x_dai; - codec->num_dai = 1; - codec->reg_cache_size = ARRAY_SIZE(aic3x_reg); - codec->reg_cache = kmemdup(aic3x_reg, sizeof(aic3x_reg), GFP_KERNEL); - if (codec->reg_cache == NULL) - return -ENOMEM; - aic3x_write(codec, AIC3X_PAGE_SELECT, PAGE0_SELECT); aic3x_write(codec, AIC3X_RESET, SOFT_RESET);
@@ -1245,42 +1224,77 @@ static int aic3x_init(struct snd_soc_codec *codec) return 0; }
-static struct snd_soc_codec *aic3x_codec; - -static int aic3x_register(struct snd_soc_codec *codec) +static int aic3x_probe(struct snd_soc_codec *codec) { - int ret; + struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec); + struct aic3x_pdata *pdata = codec->dev->platform_data; + struct aic3x_setup_data *setup = pdata->setup; + int ret = 0, i; + + codec->hw_write = (hw_write_t) i2c_master_send; + codec->control_data = aic3x->control_data;
- ret = aic3x_init(codec); - if (ret < 0) { - dev_err(codec->dev, "Failed to initialise device\n"); - return ret; + aic3x->gpio_reset = -1; + if (pdata && pdata->gpio_reset >= 0) { + ret = gpio_request(pdata->gpio_reset, "tlv320aic3x reset"); + if (ret != 0) + return ret; + aic3x->gpio_reset = pdata->gpio_reset; + gpio_direction_output(aic3x->gpio_reset, 0); }
- aic3x_codec = codec; + for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++) + aic3x->supplies[i].supply = aic3x_supply_names[i];
- ret = snd_soc_register_codec(codec); - if (ret) { - dev_err(codec->dev, "Failed to register codec\n"); - return ret; + ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(aic3x->supplies), + aic3x->supplies); + if (ret != 0) { + dev_err(codec->dev, "Failed to request supplies: %d\n", ret); + goto err_get; }
- ret = snd_soc_register_dai(&aic3x_dai); - if (ret) { - dev_err(codec->dev, "Failed to register dai\n"); - snd_soc_unregister_codec(codec); - return ret; + ret = regulator_bulk_enable(ARRAY_SIZE(aic3x->supplies), + aic3x->supplies); + if (ret != 0) { + dev_err(codec->dev, "Failed to enable supplies: %d\n", ret); + goto err_enable; }
- return 0; + if (aic3x->gpio_reset >= 0) { + udelay(1); + gpio_set_value(aic3x->gpio_reset, 1); + } + + if (setup) { + /* setup GPIO functions */ + aic3x_write(codec, AIC3X_GPIO1_REG, + (setup->gpio_func[0] & 0xf) << 4); + aic3x_write(codec, AIC3X_GPIO2_REG, + (setup->gpio_func[1] & 0xf) << 4); + } + + aic3x_init(codec); + + snd_soc_add_controls(codec, aic3x_snd_controls, + ARRAY_SIZE(aic3x_snd_controls)); + + aic3x_add_widgets(codec); + + return ret; + +err_enable: + regulator_bulk_free(ARRAY_SIZE(aic3x->supplies), aic3x->supplies); +err_get: + if (aic3x->gpio_reset >= 0) + gpio_free(aic3x->gpio_reset); + return ret; }
-static int aic3x_unregister(struct aic3x_priv *aic3x) +static int aic3x_remove(struct snd_soc_codec *codec) { - aic3x_set_bias_level(&aic3x->codec, SND_SOC_BIAS_OFF); + struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
- snd_soc_unregister_dai(&aic3x_dai); - snd_soc_unregister_codec(&aic3x->codec); + aic3x_set_bias_level(codec, SND_SOC_BIAS_OFF);
if (aic3x->gpio_reset >= 0) { gpio_set_value(aic3x->gpio_reset, 0); @@ -1289,12 +1303,25 @@ static int aic3x_unregister(struct aic3x_priv *aic3x) regulator_bulk_disable(ARRAY_SIZE(aic3x->supplies), aic3x->supplies); regulator_bulk_free(ARRAY_SIZE(aic3x->supplies), aic3x->supplies);
- kfree(aic3x); - aic3x_codec = NULL; - return 0; }
+struct snd_soc_codec_driver soc_codec_dev_aic3x = { + .name = "tlv320aic3x", + .owner = THIS_MODULE, + .read = aic3x_read_reg_cache, + .write = aic3x_write, + .set_bias_level = aic3x_set_bias_level, + .reg_cache_size = ARRAY_SIZE(aic3x_reg), + .reg_word_size = sizeof(u8), + .reg_cache_default = aic3x_reg, + .probe = aic3x_probe, + .remove = aic3x_remove, + .suspend = aic3x_suspend, + .resume = aic3x_resume, +}; +EXPORT_SYMBOL_GPL(soc_codec_dev_aic3x); + #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) /* * AIC3X 2 wire address can be up to 4 devices with device addresses @@ -1308,10 +1335,8 @@ static int aic3x_unregister(struct aic3x_priv *aic3x) static int aic3x_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { - struct snd_soc_codec *codec; struct aic3x_priv *aic3x; - struct aic3x_pdata *pdata = i2c->dev.platform_data; - int ret, i; + int ret;
aic3x = kzalloc(sizeof(struct aic3x_priv), GFP_KERNEL); if (aic3x == NULL) { @@ -1319,62 +1344,22 @@ static int aic3x_i2c_probe(struct i2c_client *i2c, return -ENOMEM; }
- codec = &aic3x->codec; - codec->dev = &i2c->dev; - snd_soc_codec_set_drvdata(codec, aic3x); - codec->control_data = i2c; - codec->hw_write = (hw_write_t) i2c_master_send; - + aic3x->control_data = i2c; i2c_set_clientdata(i2c, aic3x);
- aic3x->gpio_reset = -1; - if (pdata && pdata->gpio_reset >= 0) { - ret = gpio_request(pdata->gpio_reset, "tlv320aic3x reset"); - if (ret != 0) - goto err_gpio; - aic3x->gpio_reset = pdata->gpio_reset; - gpio_direction_output(aic3x->gpio_reset, 0); - } - - for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++) - aic3x->supplies[i].supply = aic3x_supply_names[i]; - - ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(aic3x->supplies), - aic3x->supplies); - if (ret != 0) { - dev_err(codec->dev, "Failed to request supplies: %d\n", ret); - goto err_get; - } - - ret = regulator_bulk_enable(ARRAY_SIZE(aic3x->supplies), - aic3x->supplies); - if (ret != 0) { - dev_err(codec->dev, "Failed to enable supplies: %d\n", ret); - goto err_enable; - } - - if (aic3x->gpio_reset >= 0) { - udelay(1); - gpio_set_value(aic3x->gpio_reset, 1); - } + ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &soc_codec_dev_aic3x, &aic3x_dai, 1); + if (ret < 0) + kfree(aic3x);
- return aic3x_register(codec); - -err_enable: - regulator_bulk_free(ARRAY_SIZE(aic3x->supplies), aic3x->supplies); -err_get: - if (aic3x->gpio_reset >= 0) - gpio_free(aic3x->gpio_reset); -err_gpio: - kfree(aic3x); return ret; }
static int aic3x_i2c_remove(struct i2c_client *client) { - struct aic3x_priv *aic3x = i2c_get_clientdata(client); - - return aic3x_unregister(aic3x); + snd_soc_unregister_codec(&client->dev, client->addr); + kfree(i2c_get_clientdata(client)); + return 0; }
static const struct i2c_device_id aic3x_i2c_id[] = { @@ -1409,90 +1394,27 @@ static inline void aic3x_i2c_exit(void) { i2c_del_driver(&aic3x_i2c_driver); } -#else -static inline void aic3x_i2c_init(void) { } -static inline void aic3x_i2c_exit(void) { } #endif
-static int aic3x_probe(struct platform_device *pdev) +static int __init aic3x_modinit(void) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct aic3x_setup_data *setup; - struct snd_soc_codec *codec; int ret = 0; - - codec = aic3x_codec; - if (!codec) { - dev_err(&pdev->dev, "Codec not registered\n"); - return -ENODEV; - } - - socdev->card->codec = codec; - setup = socdev->codec_data; - - if (setup) { - /* setup GPIO functions */ - aic3x_write(codec, AIC3X_GPIO1_REG, - (setup->gpio_func[0] & 0xf) << 4); - aic3x_write(codec, AIC3X_GPIO2_REG, - (setup->gpio_func[1] & 0xf) << 4); - } - - /* register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret < 0) { - printk(KERN_ERR "aic3x: failed to create pcms\n"); - goto pcm_err; +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) + ret = i2c_add_driver(&aic3x_i2c_driver); + if (ret != 0) { + printk(KERN_ERR "Failed to register TLV320AIC3x I2C driver: %d\n", + ret); } - - snd_soc_add_controls(codec, aic3x_snd_controls, - ARRAY_SIZE(aic3x_snd_controls)); - - aic3x_add_widgets(codec); - - return ret; - -pcm_err: - kfree(codec->reg_cache); +#endif return ret; } - -static int aic3x_remove(struct platform_device *pdev) -{ - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - - /* power down chip */ - if (codec->control_data) - aic3x_set_bias_level(codec, SND_SOC_BIAS_OFF); - - snd_soc_free_pcms(socdev); - snd_soc_dapm_free(socdev); - - kfree(codec->reg_cache); - - return 0; -} - -struct snd_soc_codec_device soc_codec_dev_aic3x = { - .probe = aic3x_probe, - .remove = aic3x_remove, - .suspend = aic3x_suspend, - .resume = aic3x_resume, -}; -EXPORT_SYMBOL_GPL(soc_codec_dev_aic3x); - -static int __init aic3x_modinit(void) -{ - aic3x_i2c_init(); - - return 0; -} module_init(aic3x_modinit);
static void __exit aic3x_exit(void) { - aic3x_i2c_exit(); +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) + i2c_del_driver(&aic3x_i2c_driver); +#endif } module_exit(aic3x_exit);
diff --git a/sound/soc/codecs/tlv320aic3x.h b/sound/soc/codecs/tlv320aic3x.h index 9af1c88..183a5d4 100644 --- a/sound/soc/codecs/tlv320aic3x.h +++ b/sound/soc/codecs/tlv320aic3x.h @@ -199,42 +199,6 @@ /* Default input volume */ #define DEFAULT_GAIN 0x20
-/* GPIO API */ -enum { - AIC3X_GPIO1_FUNC_DISABLED = 0, - AIC3X_GPIO1_FUNC_AUDIO_WORDCLK_ADC = 1, - AIC3X_GPIO1_FUNC_CLOCK_MUX = 2, - AIC3X_GPIO1_FUNC_CLOCK_MUX_DIV2 = 3, - AIC3X_GPIO1_FUNC_CLOCK_MUX_DIV4 = 4, - AIC3X_GPIO1_FUNC_CLOCK_MUX_DIV8 = 5, - AIC3X_GPIO1_FUNC_SHORT_CIRCUIT_IRQ = 6, - AIC3X_GPIO1_FUNC_AGC_NOISE_IRQ = 7, - AIC3X_GPIO1_FUNC_INPUT = 8, - AIC3X_GPIO1_FUNC_OUTPUT = 9, - AIC3X_GPIO1_FUNC_DIGITAL_MIC_MODCLK = 10, - AIC3X_GPIO1_FUNC_AUDIO_WORDCLK = 11, - AIC3X_GPIO1_FUNC_BUTTON_IRQ = 12, - AIC3X_GPIO1_FUNC_HEADSET_DETECT_IRQ = 13, - AIC3X_GPIO1_FUNC_HEADSET_DETECT_OR_BUTTON_IRQ = 14, - AIC3X_GPIO1_FUNC_ALL_IRQ = 16 -}; - -enum { - AIC3X_GPIO2_FUNC_DISABLED = 0, - AIC3X_GPIO2_FUNC_HEADSET_DETECT_IRQ = 2, - AIC3X_GPIO2_FUNC_INPUT = 3, - AIC3X_GPIO2_FUNC_OUTPUT = 4, - AIC3X_GPIO2_FUNC_DIGITAL_MIC_INPUT = 5, - AIC3X_GPIO2_FUNC_AUDIO_BITCLK = 8, - AIC3X_GPIO2_FUNC_HEADSET_DETECT_OR_BUTTON_IRQ = 9, - AIC3X_GPIO2_FUNC_ALL_IRQ = 10, - AIC3X_GPIO2_FUNC_SHORT_CIRCUIT_OR_AGC_IRQ = 11, - AIC3X_GPIO2_FUNC_HEADSET_OR_BUTTON_PRESS_OR_SHORT_CIRCUIT_IRQ = 12, - AIC3X_GPIO2_FUNC_SHORT_CIRCUIT_IRQ = 13, - AIC3X_GPIO2_FUNC_AGC_NOISE_IRQ = 14, - AIC3X_GPIO2_FUNC_BUTTON_PRESS_IRQ = 15 -}; - void aic3x_set_gpio(struct snd_soc_codec *codec, int gpio, int state); int aic3x_get_gpio(struct snd_soc_codec *codec, int gpio);
@@ -281,11 +245,7 @@ void aic3x_set_headset_detection(struct snd_soc_codec *codec, int detect, int aic3x_headset_detected(struct snd_soc_codec *codec); int aic3x_button_pressed(struct snd_soc_codec *codec);
-struct aic3x_setup_data { - unsigned int gpio_func[2]; -}; - -extern struct snd_soc_dai aic3x_dai; -extern struct snd_soc_codec_device soc_codec_dev_aic3x; +extern struct snd_soc_dai_driver aic3x_dai; +extern struct snd_soc_codec_driver soc_codec_dev_aic3x;
#endif /* _AIC3X_H */ diff --git a/sound/soc/codecs/tlv320dac33.c b/sound/soc/codecs/tlv320dac33.c index 2fa946c..9c1a414 100644 --- a/sound/soc/codecs/tlv320dac33.c +++ b/sound/soc/codecs/tlv320dac33.c @@ -65,8 +65,6 @@ static void dac33_calculate_times(struct snd_pcm_substream *substream); static int dac33_prepare_chip(struct snd_pcm_substream *substream);
-static struct snd_soc_codec *tlv320dac33_codec; - enum dac33_state { DAC33_IDLE = 0, DAC33_PREFILL, @@ -123,6 +121,8 @@ struct tlv320dac33_priv { unsigned int uthr;
enum dac33_state state; + enum snd_soc_control_type control_type; + void *control_data; };
static const u8 dac33_reg[DAC33_CACHEREGNUM] = { @@ -779,8 +779,7 @@ static int dac33_startup(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 tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
/* Stream started, save the substream pointer */ @@ -793,8 +792,7 @@ static void dac33_shutdown(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 tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
dac33->substream = NULL; @@ -805,8 +803,7 @@ static int dac33_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;
/* Check parameters for validity */ switch (params_rate(params)) { @@ -844,8 +841,7 @@ static int dac33_hw_params(struct snd_pcm_substream *substream, static int dac33_prepare_chip(struct snd_pcm_substream *substream) { 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 tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); unsigned int oscset, ratioset, pwr_ctrl, reg_tmp; u8 aictrl_a, aictrl_b, fifoctrl_a; @@ -1037,8 +1033,7 @@ static int dac33_prepare_chip(struct snd_pcm_substream *substream) static void dac33_calculate_times(struct snd_pcm_substream *substream) { 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 tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); unsigned int nsample_limit;
@@ -1103,8 +1098,7 @@ static int dac33_pcm_trigger(struct snd_pcm_substream *substream, int cmd, 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 tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); int ret = 0;
@@ -1137,8 +1131,7 @@ static snd_pcm_sframes_t dac33_dai_delay( 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 tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); unsigned long long t0, t1, t_now; unsigned int time_delta, uthr; @@ -1363,26 +1356,73 @@ static int dac33_set_dai_fmt(struct snd_soc_dai *codec_dai, return 0; }
-static int dac33_soc_probe(struct platform_device *pdev) +static int dac33_soc_probe(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - struct tlv320dac33_priv *dac33; - int ret = 0; + struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); + int ret = 0, i; + + codec->control_data = dac33->control_data; + codec->hw_write = (hw_write_t) i2c_master_send; + + /* Check if the reset GPIO number is valid and request it */ + if (dac33->power_gpio >= 0) { + ret = gpio_request(dac33->power_gpio, "tlv320dac33 reset"); + if (ret < 0) { + dev_err(codec->dev, + "Failed to request reset GPIO (%d)\n", + dac33->power_gpio); + return ret; + } + gpio_direction_output(dac33->power_gpio, 0); + } else { + dac33->chip_power = 1; + } + + /* Check if the IRQ number is valid and request it */ + if (dac33->irq >= 0) { + ret = request_irq(dac33->irq, dac33_interrupt_handler, + IRQF_TRIGGER_RISING | IRQF_DISABLED, + codec->name, codec); + if (ret < 0) { + dev_err(codec->dev, "Could not request IRQ%d (%d)\n", + dac33->irq, ret); + dac33->irq = -1; + } + if (dac33->irq != -1) { + /* Setup work queue */ + dac33->dac33_wq = + create_singlethread_workqueue("tlv320dac33"); + if (dac33->dac33_wq == NULL) { + free_irq(dac33->irq, codec); + ret = -ENOMEM; + goto error_wq; + } + + INIT_WORK(&dac33->work, dac33_work); + } + }
- BUG_ON(!tlv320dac33_codec); + for (i = 0; i < ARRAY_SIZE(dac33->supplies); i++) + dac33->supplies[i].supply = dac33_supply_names[i];
- codec = tlv320dac33_codec; - socdev->card->codec = codec; - dac33 = snd_soc_codec_get_drvdata(codec); + ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(dac33->supplies), + dac33->supplies);
- /* 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\n"); - goto pcm_err; + if (ret != 0) { + dev_err(codec->dev, "Failed to request supplies: %d\n", ret); + goto err_get; }
+ ret = regulator_bulk_enable(ARRAY_SIZE(dac33->supplies), + dac33->supplies); + if (ret != 0) { + dev_err(codec->dev, "Failed to enable supplies: %d\n", ret); + goto err_enable; + } + + /* Power up the codec */ + dac33_hard_power(codec, 1); + snd_soc_add_controls(codec, dac33_snd_controls, ARRAY_SIZE(dac33_snd_controls)); /* Only add the nSample controls, if we have valid IRQ number */ @@ -1394,45 +1434,63 @@ static int dac33_soc_probe(struct platform_device *pdev)
return 0;
-pcm_err: - dac33_hard_power(codec, 0); +err_enable: + regulator_bulk_free(ARRAY_SIZE(dac33->supplies), dac33->supplies); +err_get: + if (dac33->irq >= 0) { + free_irq(dac33->irq, &dac33->codec); + destroy_workqueue(dac33->dac33_wq); + } +error_wq: + if (dac33->power_gpio >= 0) + gpio_free(dac33->power_gpio); + return ret; }
-static int dac33_soc_remove(struct platform_device *pdev) +static int dac33_soc_remove(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; + struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
dac33_set_bias_level(codec, SND_SOC_BIAS_OFF);
- snd_soc_free_pcms(socdev); - snd_soc_dapm_free(socdev); + if (unlikely(dac33->chip_power)) + dac33_hard_power(&dac33->codec, 0);
+ if (dac33->power_gpio >= 0) + gpio_free(dac33->power_gpio); + if (dac33->irq >= 0) + free_irq(dac33->irq, &dac33->codec); + + regulator_bulk_disable(ARRAY_SIZE(dac33->supplies), dac33->supplies); + regulator_bulk_free(ARRAY_SIZE(dac33->supplies), dac33->supplies); + destroy_workqueue(dac33->dac33_wq); return 0; }
-static int dac33_soc_suspend(struct platform_device *pdev, pm_message_t state) +static int dac33_soc_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; - dac33_set_bias_level(codec, SND_SOC_BIAS_OFF);
return 0; }
-static int dac33_soc_resume(struct platform_device *pdev) +static int dac33_soc_resume(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - dac33_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
return 0; }
-struct snd_soc_codec_device soc_codec_dev_tlv320dac33 = { +struct snd_soc_codec_driver soc_codec_dev_tlv320dac33 = { + .name = "tlv320dac33", + .owner = THIS_MODULE, + .read = dac33_read_reg_cache, + .write = dac33_write_locked, + .set_bias_level = dac33_set_bias_level, + .reg_cache_size = ARRAY_SIZE(dac33_reg), + .reg_word_size = sizeof(u8), + .reg_cache_default = dac33_reg, .probe = dac33_soc_probe, .remove = dac33_soc_remove, .suspend = dac33_soc_suspend, @@ -1454,7 +1512,7 @@ static struct snd_soc_dai_ops dac33_dai_ops = { .set_fmt = dac33_set_dai_fmt, };
-struct snd_soc_dai dac33_dai = { +struct snd_soc_dai_driver dac33_dai = { .name = "tlv320dac33", .playback = { .stream_name = "Playback", @@ -1471,8 +1529,7 @@ static int __devinit dac33_i2c_probe(struct i2c_client *client, { struct tlv320dac33_platform_data *pdata; struct tlv320dac33_priv *dac33; - struct snd_soc_codec *codec; - int ret, i; + int ret;
if (client->dev.platform_data == NULL) { dev_err(&client->dev, "Platform data not set\n"); @@ -1484,34 +1541,8 @@ static int __devinit dac33_i2c_probe(struct i2c_client *client, if (dac33 == NULL) return -ENOMEM;
- codec = &dac33->codec; - snd_soc_codec_set_drvdata(codec, dac33); - codec->control_data = client; - - mutex_init(&codec->mutex); + dac33->control_data = client; mutex_init(&dac33->mutex); - spin_lock_init(&dac33->lock); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - codec->name = "tlv320dac33"; - codec->owner = THIS_MODULE; - codec->read = dac33_read_reg_cache; - codec->write = dac33_write_locked; - codec->hw_write = (hw_write_t) i2c_master_send; - codec->bias_level = SND_SOC_BIAS_OFF; - codec->set_bias_level = dac33_set_bias_level; - codec->idle_bias_off = 1; - codec->dai = &dac33_dai; - codec->num_dai = 1; - codec->reg_cache_size = ARRAY_SIZE(dac33_reg); - codec->reg_cache = kmemdup(dac33_reg, ARRAY_SIZE(dac33_reg), - GFP_KERNEL); - if (codec->reg_cache == NULL) { - ret = -ENOMEM; - goto error_reg; - } - i2c_set_clientdata(client, dac33);
dac33->power_gpio = pdata->power_gpio; @@ -1526,126 +1557,17 @@ static int __devinit dac33_i2c_probe(struct i2c_client *client, /* Disable FIFO use by default */ dac33->fifo_mode = DAC33_FIFO_BYPASS;
- tlv320dac33_codec = codec; - - codec->dev = &client->dev; - dac33_dai.dev = codec->dev; - - /* Check if the reset GPIO number is valid and request it */ - if (dac33->power_gpio >= 0) { - ret = gpio_request(dac33->power_gpio, "tlv320dac33 reset"); - if (ret < 0) { - dev_err(codec->dev, - "Failed to request reset GPIO (%d)\n", - dac33->power_gpio); - snd_soc_unregister_dai(&dac33_dai); - snd_soc_unregister_codec(codec); - goto error_gpio; - } - gpio_direction_output(dac33->power_gpio, 0); - } - - /* Check if the IRQ number is valid and request it */ - if (dac33->irq >= 0) { - ret = request_irq(dac33->irq, dac33_interrupt_handler, - IRQF_TRIGGER_RISING | IRQF_DISABLED, - codec->name, codec); - if (ret < 0) { - dev_err(codec->dev, "Could not request IRQ%d (%d)\n", - dac33->irq, ret); - dac33->irq = -1; - } - if (dac33->irq != -1) { - /* Setup work queue */ - dac33->dac33_wq = - create_singlethread_workqueue("tlv320dac33"); - if (dac33->dac33_wq == NULL) { - free_irq(dac33->irq, &dac33->codec); - ret = -ENOMEM; - goto error_wq; - } - - INIT_WORK(&dac33->work, dac33_work); - } - } - - for (i = 0; i < ARRAY_SIZE(dac33->supplies); i++) - dac33->supplies[i].supply = dac33_supply_names[i]; - - ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(dac33->supplies), - dac33->supplies); - - if (ret != 0) { - dev_err(codec->dev, "Failed to request supplies: %d\n", ret); - goto err_get; - } - - /* Read the tlv320dac33 ID registers */ - ret = dac33_hard_power(codec, 1); - if (ret != 0) { - dev_err(codec->dev, "Failed to power up codec: %d\n", ret); - goto error_codec; - } - dac33_read_id(codec); - dac33_hard_power(codec, 0); - - ret = snd_soc_register_codec(codec); - if (ret != 0) { - dev_err(codec->dev, "Failed to register codec: %d\n", ret); - goto error_codec; - } - - ret = snd_soc_register_dai(&dac33_dai); - if (ret != 0) { - dev_err(codec->dev, "Failed to register DAI: %d\n", ret); - snd_soc_unregister_codec(codec); - goto error_codec; - } - - return ret; - -error_codec: - regulator_bulk_free(ARRAY_SIZE(dac33->supplies), dac33->supplies); -err_get: - if (dac33->irq >= 0) { - free_irq(dac33->irq, &dac33->codec); - destroy_workqueue(dac33->dac33_wq); - } -error_wq: - if (dac33->power_gpio >= 0) - gpio_free(dac33->power_gpio); -error_gpio: - kfree(codec->reg_cache); -error_reg: - tlv320dac33_codec = NULL; - kfree(dac33); - + ret = snd_soc_register_codec(&client->dev, client->addr, + &soc_codec_dev_tlv320dac33, &dac33_dai, 1); + if (ret < 0) + kfree(dac33); return ret; }
static int __devexit dac33_i2c_remove(struct i2c_client *client) { - struct tlv320dac33_priv *dac33; - - dac33 = i2c_get_clientdata(client); - - if (unlikely(dac33->chip_power)) - dac33_hard_power(&dac33->codec, 0); - - if (dac33->power_gpio >= 0) - gpio_free(dac33->power_gpio); - if (dac33->irq >= 0) - free_irq(dac33->irq, &dac33->codec); - - regulator_bulk_free(ARRAY_SIZE(dac33->supplies), dac33->supplies); - - destroy_workqueue(dac33->dac33_wq); - snd_soc_unregister_dai(&dac33_dai); - snd_soc_unregister_codec(&dac33->codec); - kfree(dac33->codec.reg_cache); - kfree(dac33); - tlv320dac33_codec = NULL; - + snd_soc_unregister_codec(&client->dev, client->addr); + kfree(i2c_get_clientdata(client)); return 0; }
diff --git a/sound/soc/codecs/tlv320dac33.h b/sound/soc/codecs/tlv320dac33.h index eb8ae07..7498c10 100644 --- a/sound/soc/codecs/tlv320dac33.h +++ b/sound/soc/codecs/tlv320dac33.h @@ -261,7 +261,7 @@ #define TLV320DAC33_MCLK 0 #define TLV320DAC33_SLEEPCLK 1
-extern struct snd_soc_dai dac33_dai; -extern struct snd_soc_codec_device soc_codec_dev_tlv320dac33; +extern struct snd_soc_dai_driver dac33_dai; +extern struct snd_soc_codec_driver soc_codec_dev_tlv320dac33;
#endif /* __TLV320DAC33_H */ diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c index 8d36bfa..803f5bb 100644 --- a/sound/soc/codecs/twl4030.c +++ b/sound/soc/codecs/twl4030.c @@ -274,11 +274,9 @@ static inline void twl4030_reset_registers(struct snd_soc_codec *codec)
}
-static void twl4030_init_chip(struct platform_device *pdev) +static void twl4030_init_chip(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct twl4030_setup_data *setup = socdev->codec_data; - struct snd_soc_codec *codec = socdev->card->codec; + struct twl4030_setup_data *setup = dev_get_platdata(codec->dev); struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); u8 reg, byte; int i = 0; @@ -613,7 +611,7 @@ static int micpath_event(struct snd_soc_dapm_widget *w, static int pin_name##pga_event(struct snd_soc_dapm_widget *w, \ struct snd_kcontrol *kcontrol, int event) \ { \ - struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(w->codec); \ + struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(w->codec); \ \ switch (event) { \ case SND_SOC_DAPM_POST_PMU: \ @@ -742,9 +740,7 @@ static int aif_event(struct snd_soc_dapm_widget *w,
static void headset_ramp(struct snd_soc_codec *codec, int ramp) { - struct snd_soc_device *socdev = codec->socdev; - struct twl4030_setup_data *setup = socdev->codec_data; - + struct twl4030_codec_audio_data *setup = codec->dev->platform_data; unsigned char hs_gain, hs_pop; struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); /* Base values for ramp delay calculation: 2^19 - 2^26 */ @@ -1712,8 +1708,7 @@ static int twl4030_startup(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 twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
if (twl4030->master_substream) { @@ -1743,8 +1738,7 @@ static void twl4030_shutdown(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 twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
if (twl4030->master_substream == substream) @@ -1769,8 +1763,7 @@ static int twl4030_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 twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); u8 mode, old_mode, format, old_format;
@@ -2004,8 +1997,7 @@ static int twl4030_voice_startup(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 twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); u8 mode;
@@ -2038,8 +2030,7 @@ static void twl4030_voice_shutdown(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;
/* Enable voice digital filters */ twl4030_voice_enable(codec, substream->stream, 0); @@ -2049,8 +2040,7 @@ static int twl4030_voice_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, 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 twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); u8 old_mode, mode;
@@ -2180,7 +2170,7 @@ static int twl4030_voice_set_tristate(struct snd_soc_dai *dai, int tristate) #define TWL4030_RATES (SNDRV_PCM_RATE_8000_48000) #define TWL4030_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FORMAT_S24_LE)
-static struct snd_soc_dai_ops twl4030_dai_ops = { +struct snd_soc_dai_ops twl4030_dai_ops = { .startup = twl4030_startup, .shutdown = twl4030_shutdown, .hw_params = twl4030_hw_params, @@ -2198,7 +2188,7 @@ static struct snd_soc_dai_ops twl4030_dai_voice_ops = { .set_tristate = twl4030_voice_set_tristate, };
-struct snd_soc_dai twl4030_dai[] = { +struct snd_soc_dai_driver twl4030_dai[] = { { .name = "twl4030", .playback = { @@ -2234,152 +2224,81 @@ struct snd_soc_dai twl4030_dai[] = { }; EXPORT_SYMBOL_GPL(twl4030_dai);
-static int twl4030_soc_suspend(struct platform_device *pdev, pm_message_t state) -{ - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec;
+static int twl4030_soc_suspend(struct snd_soc_codec *codec, + pm_message_t state) +{ twl4030_set_bias_level(codec, SND_SOC_BIAS_OFF); - return 0; }
-static int twl4030_soc_resume(struct platform_device *pdev) +static int twl4030_soc_resume(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - twl4030_set_bias_level(codec, SND_SOC_BIAS_STANDBY); return 0; }
-static struct snd_soc_codec *twl4030_codec; - -static int twl4030_soc_probe(struct platform_device *pdev) -{ - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - int ret; - - BUG_ON(!twl4030_codec); - - codec = twl4030_codec; - socdev->card->codec = codec; - - twl4030_init_chip(pdev); - - /* register pcms */ - 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, twl4030_snd_controls, - ARRAY_SIZE(twl4030_snd_controls)); - twl4030_add_widgets(codec); - - return 0; -} - -static int twl4030_soc_remove(struct platform_device *pdev) +static int twl4030_soc_probe(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - - /* Reset registers to their chip default before leaving */ - twl4030_reset_registers(codec); - twl4030_set_bias_level(codec, SND_SOC_BIAS_OFF); - snd_soc_free_pcms(socdev); - snd_soc_dapm_free(socdev); - - return 0; -} - -static int __devinit twl4030_codec_probe(struct platform_device *pdev) -{ - struct twl4030_codec_audio_data *pdata = pdev->dev.platform_data; - struct snd_soc_codec *codec; + struct twl4030_codec_audio_data *pdata = codec->dev->platform_data; struct twl4030_priv *twl4030; - int ret;
if (!pdata) { - dev_err(&pdev->dev, "platform_data is missing\n"); + dev_err(codec->dev, "platform_data is missing\n"); return -EINVAL; }
twl4030 = kzalloc(sizeof(struct twl4030_priv), GFP_KERNEL); if (twl4030 == NULL) { - dev_err(&pdev->dev, "Can not allocate memroy\n"); + dev_err(codec->dev, "Can not allocate memroy\n"); return -ENOMEM; }
- codec = &twl4030->codec; - snd_soc_codec_set_drvdata(codec, twl4030); - codec->dev = &pdev->dev; - twl4030_dai[0].dev = &pdev->dev; - twl4030_dai[1].dev = &pdev->dev; - - mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - codec->name = "twl4030"; - codec->owner = THIS_MODULE; - codec->read = twl4030_read_reg_cache; - codec->write = twl4030_write; - codec->set_bias_level = twl4030_set_bias_level; - codec->idle_bias_off = 1; - codec->dai = twl4030_dai; - codec->num_dai = ARRAY_SIZE(twl4030_dai); - codec->reg_cache_size = sizeof(twl4030_reg); - codec->reg_cache = kmemdup(twl4030_reg, sizeof(twl4030_reg), - GFP_KERNEL); - if (codec->reg_cache == NULL) { - ret = -ENOMEM; - goto error_cache; - } - - platform_set_drvdata(pdev, twl4030); - twl4030_codec = codec; + dev_set_drvdata(codec->dev, twl4030);
/* Set the defaults, and power up the codec */ twl4030->sysclk = twl4030_codec_get_mclk() / 1000; codec->bias_level = SND_SOC_BIAS_OFF;
- ret = snd_soc_register_codec(codec); - if (ret != 0) { - dev_err(codec->dev, "Failed to register codec: %d\n", ret); - goto error_codec; - } + twl4030_init_chip(codec);
- ret = snd_soc_register_dais(&twl4030_dai[0], ARRAY_SIZE(twl4030_dai)); - if (ret != 0) { - dev_err(codec->dev, "Failed to register DAIs: %d\n", ret); - snd_soc_unregister_codec(codec); - goto error_codec; - } + snd_soc_add_controls(codec, twl4030_snd_controls, + ARRAY_SIZE(twl4030_snd_controls)); + twl4030_add_widgets(codec); + return 0; +}
+static int twl4030_soc_remove(struct snd_soc_codec *codec) +{ + twl4030_set_bias_level(codec, SND_SOC_BIAS_OFF); return 0; +}
-error_codec: - twl4030_codec_enable(codec, 0); - kfree(codec->reg_cache); -error_cache: - kfree(twl4030); - return ret; +struct snd_soc_codec_driver soc_codec_dev_twl4030 = { + .name = "TWL4030", + .owner = THIS_MODULE, + .probe = twl4030_soc_probe, + .remove = twl4030_soc_remove, + .suspend = twl4030_soc_suspend, + .resume = twl4030_soc_resume, + .read = twl4030_read_reg_cache, + .write = twl4030_write, + .set_bias_level = twl4030_set_bias_level, + .reg_cache_size = sizeof(twl4030_reg), + .reg_word_size = sizeof(u8), + .reg_cache_default = twl4030_reg, +}; +EXPORT_SYMBOL_GPL(soc_codec_dev_twl4030); + +static int __devinit twl4030_codec_probe(struct platform_device *pdev) +{ + return snd_soc_register_codec(&pdev->dev, pdev->id, &soc_codec_dev_twl4030, + twl4030_dai, ARRAY_SIZE(twl4030_dai)); }
static int __devexit twl4030_codec_remove(struct platform_device *pdev) { - struct twl4030_priv *twl4030 = platform_get_drvdata(pdev); - - snd_soc_unregister_dais(&twl4030_dai[0], ARRAY_SIZE(twl4030_dai)); - snd_soc_unregister_codec(&twl4030->codec); - kfree(twl4030->codec.reg_cache); - kfree(twl4030); - - twl4030_codec = NULL; + snd_soc_unregister_codec(&pdev->dev, pdev->id); return 0; }
@@ -2406,14 +2325,6 @@ static void __exit twl4030_exit(void) } module_exit(twl4030_exit);
-struct snd_soc_codec_device soc_codec_dev_twl4030 = { - .probe = twl4030_soc_probe, - .remove = twl4030_soc_remove, - .suspend = twl4030_soc_suspend, - .resume = twl4030_soc_resume, -}; -EXPORT_SYMBOL_GPL(soc_codec_dev_twl4030); - MODULE_DESCRIPTION("ASoC TWL4030 codec driver"); MODULE_AUTHOR("Steve Sakoman"); MODULE_LICENSE("GPL"); diff --git a/sound/soc/codecs/twl4030.h b/sound/soc/codecs/twl4030.h index 788e3d1..42a2014 100644 --- a/sound/soc/codecs/twl4030.h +++ b/sound/soc/codecs/twl4030.h @@ -36,8 +36,8 @@ #define TWL4030_DAI_HIFI 0 #define TWL4030_DAI_VOICE 1
-extern struct snd_soc_dai twl4030_dai[2]; -extern struct snd_soc_codec_device soc_codec_dev_twl4030; +extern struct snd_soc_dai_driver twl4030_dai[2]; +extern struct snd_soc_codec_driver soc_codec_dev_twl4030;
struct twl4030_setup_data { unsigned int ramp_delay_value; diff --git a/sound/soc/codecs/twl6040.c b/sound/soc/codecs/twl6040.c index 85dd4fb..e65ad82 100644 --- a/sound/soc/codecs/twl6040.c +++ b/sound/soc/codecs/twl6040.c @@ -45,7 +45,8 @@
/* codec private data */ struct twl6040_data { - struct snd_soc_codec codec; + enum snd_soc_control_type control_type; + void *control_data; int audpwron; int naudint; int codec_powered; @@ -770,8 +771,7 @@ static int twl6040_startup(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 twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
if (!priv->sysclk) { @@ -803,8 +803,7 @@ static int twl6040_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 twl6040_data *priv = snd_soc_codec_get_drvdata(codec); u8 lppllctl; int rate; @@ -839,8 +838,7 @@ static int twl6040_trigger(struct snd_pcm_substream *substream, int cmd, 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 twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
switch (cmd) { @@ -978,7 +976,7 @@ static struct snd_soc_dai_ops twl6040_dai_ops = { .set_sysclk = twl6040_set_dai_sysclk, };
-struct snd_soc_dai twl6040_dai = { +struct snd_soc_dai_driver twl6040_dai = { .name = "twl6040", .playback = { .stream_name = "Playback", @@ -999,21 +997,15 @@ struct snd_soc_dai twl6040_dai = { EXPORT_SYMBOL_GPL(twl6040_dai);
#ifdef CONFIG_PM -static int twl6040_suspend(struct platform_device *pdev, pm_message_t state) +static int twl6040_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; - twl6040_set_bias_level(codec, SND_SOC_BIAS_OFF);
return 0; }
-static int twl6040_resume(struct platform_device *pdev) +static int twl6040_resume(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - twl6040_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
return 0; @@ -1023,68 +1015,9 @@ static int twl6040_resume(struct platform_device *pdev) #define twl6040_resume NULL #endif
-static struct snd_soc_codec *twl6040_codec; - -static int twl6040_probe(struct platform_device *pdev) -{ - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - int ret = 0; - - BUG_ON(!twl6040_codec); - - codec = twl6040_codec; - socdev->card->codec = codec; - - /* register pcms */ - 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, twl6040_snd_controls, - ARRAY_SIZE(twl6040_snd_controls)); - twl6040_add_widgets(codec); - - if (ret < 0) { - dev_err(&pdev->dev, "failed to register card\n"); - goto card_err; - } - - return ret; - -card_err: - snd_soc_free_pcms(socdev); - snd_soc_dapm_free(socdev); - return ret; -} - -static int twl6040_remove(struct platform_device *pdev) -{ - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - - twl6040_set_bias_level(codec, SND_SOC_BIAS_OFF); - snd_soc_free_pcms(socdev); - snd_soc_dapm_free(socdev); - kfree(codec); - - return 0; -} - -struct snd_soc_codec_device soc_codec_dev_twl6040 = { - .probe = twl6040_probe, - .remove = twl6040_remove, - .suspend = twl6040_suspend, - .resume = twl6040_resume, -}; -EXPORT_SYMBOL_GPL(soc_codec_dev_twl6040); - -static int __devinit twl6040_codec_probe(struct platform_device *pdev) +static int twl6040_probe(struct snd_soc_codec *codec) { - struct twl4030_codec_data *twl_codec = pdev->dev.platform_data; - struct snd_soc_codec *codec; + struct twl4030_codec_data *twl_codec = codec->dev->platform_data; struct twl6040_data *priv; int audpwron, naudint; int ret = 0; @@ -1092,6 +1025,7 @@ static int __devinit twl6040_codec_probe(struct platform_device *pdev) priv = kzalloc(sizeof(struct twl6040_data), GFP_KERNEL); if (priv == NULL) return -ENOMEM; + snd_soc_codec_set_drvdata(codec, priv);
if (twl_codec) { audpwron = twl_codec->audpwron_gpio; @@ -1104,29 +1038,6 @@ static int __devinit twl6040_codec_probe(struct platform_device *pdev) priv->audpwron = audpwron; priv->naudint = naudint;
- codec = &priv->codec; - codec->dev = &pdev->dev; - twl6040_dai.dev = &pdev->dev; - - codec->name = "twl6040"; - codec->owner = THIS_MODULE; - codec->read = twl6040_read_reg_cache; - codec->write = twl6040_write; - codec->set_bias_level = twl6040_set_bias_level; - snd_soc_codec_set_drvdata(codec, priv); - codec->dai = &twl6040_dai; - codec->num_dai = 1; - codec->reg_cache_size = ARRAY_SIZE(twl6040_reg); - codec->reg_cache = kmemdup(twl6040_reg, sizeof(twl6040_reg), - GFP_KERNEL); - if (codec->reg_cache == NULL) { - ret = -ENOMEM; - goto cache_err; - } - - mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); init_completion(&priv->ready);
if (gpio_is_valid(audpwron)) { @@ -1169,23 +1080,12 @@ static int __devinit twl6040_codec_probe(struct platform_device *pdev) if (ret) goto irq_err;
- ret = snd_soc_register_codec(codec); - if (ret) - goto reg_err; - - twl6040_codec = codec; - - ret = snd_soc_register_dai(&twl6040_dai); - if (ret) - goto dai_err; + snd_soc_add_controls(codec, twl6040_snd_controls, + ARRAY_SIZE(twl6040_snd_controls)); + twl6040_add_widgets(codec);
return 0;
-dai_err: - snd_soc_unregister_codec(codec); - twl6040_codec = NULL; -reg_err: - twl6040_set_bias_level(codec, SND_SOC_BIAS_OFF); irq_err: if (naudint) free_irq(naudint, codec); @@ -1193,30 +1093,54 @@ gpio2_err: if (gpio_is_valid(audpwron)) gpio_free(audpwron); gpio1_err: - kfree(codec->reg_cache); -cache_err: kfree(priv); return ret; }
-static int __devexit twl6040_codec_remove(struct platform_device *pdev) +static int twl6040_remove(struct snd_soc_codec *codec) { - struct twl6040_data *priv = snd_soc_codec_get_drvdata(twl6040_codec); + struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); int audpwron = priv->audpwron; int naudint = priv->naudint;
+ twl6040_set_bias_level(codec, SND_SOC_BIAS_OFF); + if (gpio_is_valid(audpwron)) gpio_free(audpwron);
if (naudint) - free_irq(naudint, twl6040_codec); + free_irq(naudint, codec);
- snd_soc_unregister_dai(&twl6040_dai); - snd_soc_unregister_codec(twl6040_codec); + kfree(priv);
- kfree(twl6040_codec); - twl6040_codec = NULL; + return 0; +}
+struct snd_soc_codec_driver soc_codec_dev_twl6040 = { + .name = "twl6040", + .owner = THIS_MODULE, + .probe = twl6040_probe, + .remove = twl6040_remove, + .suspend = twl6040_suspend, + .resume = twl6040_resume, + .read = twl6040_read_reg_cache, + .write = twl6040_write, + .set_bias_level = twl6040_set_bias_level, + .reg_cache_size = ARRAY_SIZE(twl6040_reg), + .reg_word_size = sizeof(u8), + .reg_cache_default = twl6040_reg, +}; +EXPORT_SYMBOL_GPL(soc_codec_dev_twl6040); + +static int __devinit twl6040_codec_probe(struct platform_device *pdev) +{ + return snd_soc_register_codec(&pdev->dev, pdev->id, + &soc_codec_dev_twl6040, &twl6040_dai, 1); +} + +static int __devexit twl6040_codec_remove(struct platform_device *pdev) +{ + snd_soc_unregister_codec(&pdev->dev, pdev->id); return 0; }
diff --git a/sound/soc/codecs/twl6040.h b/sound/soc/codecs/twl6040.h index c472070..8c55db8 100644 --- a/sound/soc/codecs/twl6040.h +++ b/sound/soc/codecs/twl6040.h @@ -135,7 +135,7 @@ #define TWL6040_HPPLL_ID 1 #define TWL6040_LPPLL_ID 2
-extern struct snd_soc_dai twl6040_dai; -extern struct snd_soc_codec_device soc_codec_dev_twl6040; +extern struct snd_soc_dai_driver twl6040_dai; +extern struct snd_soc_codec_driver soc_codec_dev_twl6040;
#endif /* End of __TWL6040_H__ */
Hello Liam,
I'm on holiday, and I have limited access to e-mail, but I did taken a brief look at the series.. I have few question: Is the support for the former codec->idle_bias_off is gone? This patch removes it from the tlv320dac33, and t2l4030 codec drivers. I'm not really sure about the restructure of the tlv320dac33 driver: - The codec ID register read has been removed, which is really useful, and it is going to be used to enable/disable features of DAC33 based on the ID. - Originally the codec was off by default, now it is on all the time. - What is the reason to move the IRQ, GPIO, and regulator request from the i2c_probe to soc_probe?
Some of these valid for the twl4030 codec as well (especially the idle_bias_off support).
I don't claim, that I have checked all the patches, and changes, but at least with the tlv320dac33, and twl4030 codec drivers I can see some unwanted (for me) PM related regressions. Are these removals intentional?
Thanks, Peter
________________________________________ From: alsa-devel-bounces@alsa-project.org [alsa-devel-bounces@alsa-project.org] On Behalf Of ext Liam Girdwood [lrg@slimlogic.co.uk] Sent: Friday, June 25, 2010 8:52 PM To: alsa-devel@alsa-project.org Cc: Mark Brown; Liam Girdwood Subject: [alsa-devel] [RFC 04/16] ASoC: multi-component - TI CODECs
Move TI CODECs to multi-component
This patch changes the probe() and remove() of the CODEC drivers as follows:-
o Make CODEC driver a platform device (non MFD codecs only) o Moved all struct snd_soc_codec list, mutex, etc initialiasation to core. o Removed all static codec pointers (drivers now support > 1 codec dev) o snd_soc_register_pcms() now done by core. o snd_soc_register_dai() folded into snd_soc_register_codec(). o codec cache can now be malloc()ed by core.
Other required changes due to multi-component model :-
o tlv320aic3x: no more "setup_data" from ASoC machine drivers, platform data must be set in one place only. Moved platform defs out into platorm header.
On Wed, Jun 30, 2010 at 02:08:11PM +0200, peter.ujfalusi@nokia.com wrote:
Is the support for the former codec->idle_bias_off is gone? This patch removes it from the tlv320dac33, and t2l4030 codec drivers.
No, that is still present - it's an error in the conversion (probably caused by forward porting changes from prior to the update I guess).
On Wed, Jun 30, 2010 at 02:08:11PM +0200, peter.ujfalusi@nokia.com wrote:
- What is the reason to move the IRQ, GPIO, and regulator request from the i2c_probe to soc_probe?
So, the theory here is that when you've got both I2C and SPI on a single CODEC all the basic setup code tends to be identical over all buses (as it is with the current register() functions. Personally I do find this a bit strange since it feels better to have the driver check for all the things it needs before it has the subsystem go and try to do broader setup work but it does do the code sharing job.
On Wed, 2010-06-30 at 14:08 +0200, peter.ujfalusi@nokia.com wrote:
Hello Liam,
I'm on holiday, and I have limited access to e-mail, but I did taken a brief look at the series..
Same here, I'm just back from some travels....
I have few question: Is the support for the former codec->idle_bias_off is gone? This patch removes it from the tlv320dac33, and t2l4030 codec drivers. I'm not really sure about the restructure of the tlv320dac33 driver:
- The codec ID register read has been removed, which is really useful, and it is going to be used to enable/disable features of DAC33 based on the ID.
- Originally the codec was off by default, now it is on all the time.
- What is the reason to move the IRQ, GPIO, and regulator request from the i2c_probe to soc_probe?
Some of these valid for the twl4030 codec as well (especially the idle_bias_off support).
I don't claim, that I have checked all the patches, and changes, but at least with the tlv320dac33, and twl4030 codec drivers I can see some unwanted (for me) PM related regressions. Are these removals intentional?
Nope, this can all be explained my merge issues since both these codecs did go though a lot of churn in the last few months. I'll fix up soon.
Thanks
Liam
-----Original Message----- From: alsa-devel-bounces@alsa-project.org [mailto:alsa-devel-bounces@alsa-project.org] On Behalf Of Liam Girdwood Sent: Friday, June 25, 2010 11:23 PM To: alsa-devel@alsa-project.org Cc: Mark Brown; Liam Girdwood Subject: [alsa-devel] [RFC 04/16] ASoC: multi-component - TI CODECs
Move TI CODECs to multi-component
[...] o codec cache can now be malloc()ed by core.
[...]
Hi Liam,
For the AIC3x codec I saw that sysfs entry was missing. Is the malloc()to be done in the evm file somewhere?
Regards, Vaibhav
Moving to multi-component model.
Since all codecs are regular kernel devices now (with platform data) is of-simple still required ? If not, this file will be removed.
Signed-off-by: Liam Girdwood lrg@slimlogic.co.uk --- include/sound/soc-of-simple.h | 4 ++-- sound/soc/fsl/soc-of-simple.c | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/include/sound/soc-of-simple.h b/include/sound/soc-of-simple.h index a064e19..daa161f 100644 --- a/include/sound/soc-of-simple.h +++ b/include/sound/soc-of-simple.h @@ -12,8 +12,8 @@ #include <linux/of.h> #include <sound/soc.h>
-int of_snd_soc_register_codec(struct snd_soc_codec_device *codec_dev, - void *codec_data, struct snd_soc_dai *dai, +int of_snd_soc_register_codec(struct snd_soc_codec *codec, + struct snd_soc_dai *dai, struct device_node *node);
int of_snd_soc_register_platform(struct snd_soc_platform *platform, diff --git a/sound/soc/fsl/soc-of-simple.c b/sound/soc/fsl/soc-of-simple.c index 3bc13fd..3335296 100644 --- a/sound/soc/fsl/soc-of-simple.c +++ b/sound/soc/fsl/soc-of-simple.c @@ -99,8 +99,8 @@ static void of_snd_soc_register_device(struct of_snd_soc_device *of_soc)
}
-int of_snd_soc_register_codec(struct snd_soc_codec_device *codec_dev, - void *codec_data, struct snd_soc_dai *dai, +int of_snd_soc_register_codec(struct snd_soc_codec *codec, + struct snd_soc_dai *dai, struct device_node *node) { struct of_snd_soc_device *of_soc; @@ -116,8 +116,6 @@ int of_snd_soc_register_codec(struct snd_soc_codec_device *codec_dev, }
/* Store the codec data */ - of_soc->device.codec_data = codec_data; - of_soc->device.codec_dev = codec_dev; of_soc->dai_link.name = (char *)node->name; of_soc->dai_link.stream_name = (char *)node->name; of_soc->dai_link.codec_dai = dai;
Moved generic codecs to multi-component model.
This patch changes the probe() and remove() of the CODEC drivers as follows:-
o Make CODEC driver a platform device (non MFD codecs only) o Moved all struct snd_soc_codec list, mutex, etc initialiasation to core. o Removed all static codec pointers (drivers now support > 1 codec dev) o snd_soc_register_pcms() now done by core. o snd_soc_register_dai() folded into snd_soc_register_codec(). o codec cache can now be malloc()ed by core.
Signed-off-by: Liam Girdwood lrg@slimlogic.co.uk --- sound/soc/codecs/ac97.c | 122 ++++++++++++++++------------------ sound/soc/codecs/ac97.h | 4 +- sound/soc/codecs/spdif_transciever.c | 100 ++------------------------- sound/soc/codecs/spdif_transciever.h | 4 +- 4 files changed, 69 insertions(+), 161 deletions(-)
diff --git a/sound/soc/codecs/ac97.c b/sound/soc/codecs/ac97.c index 1f5e57a..8e5e199 100644 --- a/sound/soc/codecs/ac97.c +++ b/sound/soc/codecs/ac97.c @@ -30,8 +30,7 @@ static int ac97_prepare(struct snd_pcm_substream *substream, { struct snd_pcm_runtime *runtime = substream->runtime; 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;
int reg = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ? AC97_PCM_FRONT_DAC_RATE : AC97_PCM_LR_ADC_RATE; @@ -46,7 +45,7 @@ static struct snd_soc_dai_ops ac97_dai_ops = { .prepare = ac97_prepare, };
-struct snd_soc_dai ac97_dai = { +struct snd_soc_dai_driver ac97_dai = { .name = "AC97 HiFi", .ac97_control = 1, .playback = { @@ -78,95 +77,49 @@ static int ac97_write(struct snd_soc_codec *codec, unsigned int reg, return 0; }
-static int ac97_soc_probe(struct platform_device *pdev) +static int ac97_soc_probe(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_card *card = socdev->card; - struct snd_soc_codec *codec; struct snd_ac97_bus *ac97_bus; struct snd_ac97_template ac97_template; - int i; - int ret = 0; + int ret;
printk(KERN_INFO "AC97 SoC Audio Codec %s\n", AC97_VERSION);
- socdev->card->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); - if (!socdev->card->codec) - return -ENOMEM; - codec = socdev->card->codec; - mutex_init(&codec->mutex); - - codec->name = "AC97"; - codec->owner = THIS_MODULE; - codec->dai = &ac97_dai; - codec->num_dai = 1; - codec->write = ac97_write; - codec->read = ac97_read; - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - /* register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret < 0) - goto err; + ret = snd_soc_new_ac97_codec(codec, &soc_ac97_ops, 0); + if (ret < 0) { + printk(KERN_ERR "ASoC: failed to init gen ac97 glue\n"); + return ret; + }
/* add codec as bus device for standard ac97 */ - ret = snd_ac97_bus(codec->card, 0, &soc_ac97_ops, NULL, &ac97_bus); + ret = snd_ac97_bus(codec->snd_card, 0, &soc_ac97_ops, NULL, &ac97_bus); if (ret < 0) - goto bus_err; + return ret;
memset(&ac97_template, 0, sizeof(struct snd_ac97_template)); ret = snd_ac97_mixer(ac97_bus, &ac97_template, &codec->ac97); if (ret < 0) - goto bus_err; - - for (i = 0; i < card->num_links; i++) { - if (card->dai_link[i].codec_dai->ac97_control) { - snd_ac97_dev_add_pdata(codec->ac97, - card->dai_link[i].cpu_dai->ac97_pdata); - } - } + return ret;
return 0; - -bus_err: - snd_soc_free_pcms(socdev); - -err: - kfree(socdev->card->codec); - socdev->card->codec = NULL; - return ret; }
-static int ac97_soc_remove(struct platform_device *pdev) +static int ac97_soc_remove(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - - if (!codec) - return 0; - - snd_soc_free_pcms(socdev); - kfree(socdev->card->codec); - return 0; }
#ifdef CONFIG_PM -static int ac97_soc_suspend(struct platform_device *pdev, pm_message_t msg) +static int ac97_soc_suspend(struct snd_soc_codec *codec, pm_message_t msg) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - - snd_ac97_suspend(socdev->card->codec->ac97); + snd_ac97_suspend(codec->ac97);
return 0; }
-static int ac97_soc_resume(struct platform_device *pdev) +static int ac97_soc_resume(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - - snd_ac97_resume(socdev->card->codec->ac97); + snd_ac97_resume(codec->ac97);
return 0; } @@ -175,7 +128,11 @@ static int ac97_soc_resume(struct platform_device *pdev) #define ac97_soc_resume NULL #endif
-struct snd_soc_codec_device soc_codec_dev_ac97 = { +struct snd_soc_codec_driver soc_codec_dev_ac97 = { + .name = "AC97", + .owner = THIS_MODULE, + .write = ac97_write, + .read = ac97_read, .probe = ac97_soc_probe, .remove = ac97_soc_remove, .suspend = ac97_soc_suspend, @@ -183,6 +140,41 @@ struct snd_soc_codec_device soc_codec_dev_ac97 = { }; EXPORT_SYMBOL_GPL(soc_codec_dev_ac97);
+ +static __devinit int ac97_probe(struct platform_device *pdev) +{ + return snd_soc_register_codec(&pdev->dev, pdev->id, + &soc_codec_dev_ac97, &ac97_dai, 1); +} + +static int __devexit ac97_remove(struct platform_device *pdev) +{ + snd_soc_unregister_codec(&pdev->dev, pdev->id); + return 0; +} + +static struct platform_driver ac97_codec_driver = { + .driver = { + .name = "ac97-soc-codec", + .owner = THIS_MODULE, + }, + + .probe = ac97_probe, + .remove = __devexit_p(ac97_remove), +}; + +static int __init ac97_init(void) +{ + return platform_driver_register(&ac97_codec_driver); +} +module_init(ac97_init); + +static void __exit ac97_exit(void) +{ + platform_driver_unregister(&ac97_codec_driver); +} +module_exit(ac97_exit); + MODULE_DESCRIPTION("Soc Generic AC97 driver"); MODULE_AUTHOR("Liam Girdwood"); MODULE_LICENSE("GPL"); diff --git a/sound/soc/codecs/ac97.h b/sound/soc/codecs/ac97.h index 281aa42..a924659 100644 --- a/sound/soc/codecs/ac97.h +++ b/sound/soc/codecs/ac97.h @@ -13,7 +13,7 @@ #ifndef __LINUX_SND_SOC_AC97_H #define __LINUX_SND_SOC_AC97_H
-extern struct snd_soc_codec_device soc_codec_dev_ac97; -extern struct snd_soc_dai ac97_dai; +extern struct snd_soc_codec_driver soc_codec_dev_ac97; +extern struct snd_soc_dai_driver ac97_dai;
#endif diff --git a/sound/soc/codecs/spdif_transciever.c b/sound/soc/codecs/spdif_transciever.c index 9119836..683ba46 100644 --- a/sound/soc/codecs/spdif_transciever.c +++ b/sound/soc/codecs/spdif_transciever.c @@ -28,49 +28,13 @@ MODULE_LICENSE("GPL"); #define STUB_RATES SNDRV_PCM_RATE_8000_96000 #define STUB_FORMATS SNDRV_PCM_FMTBIT_S16_LE
-static struct snd_soc_codec *spdif_dit_codec;
-static int spdif_dit_codec_probe(struct platform_device *pdev) -{ - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - int ret; - - if (spdif_dit_codec == NULL) { - dev_err(&pdev->dev, "Codec device not registered\n"); - return -ENODEV; - } - - socdev->card->codec = spdif_dit_codec; - codec = spdif_dit_codec; - - 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 err_create_pcms; - } - - return 0; - -err_create_pcms: - return ret; -} - -static int spdif_dit_codec_remove(struct platform_device *pdev) -{ - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - - snd_soc_free_pcms(socdev); - - return 0; -} +struct snd_soc_codec_driver soc_codec_spdif_dit = { + .name = "DIT", + .owner = THIS_MODULE, +}; EXPORT_SYMBOL_GPL(soc_codec_spdif_dit);
-struct snd_soc_codec_device soc_codec_dev_spdif_dit = { - .probe = spdif_dit_codec_probe, - .remove = spdif_dit_codec_remove, -}; EXPORT_SYMBOL_GPL(soc_codec_dev_spdif_dit); - -struct snd_soc_dai dit_stub_dai = { +struct snd_soc_dai_driver dit_stub_dai = { .name = "DIT", .playback = { .stream_name = "Playback", @@ -84,61 +48,13 @@ EXPORT_SYMBOL_GPL(dit_stub_dai);
static int spdif_dit_probe(struct platform_device *pdev) { - struct snd_soc_codec *codec; - int ret; - - if (spdif_dit_codec) { - dev_err(&pdev->dev, "Another Codec is registered\n"); - ret = -EINVAL; - goto err_reg_codec; - } - - codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); - if (codec == NULL) - return -ENOMEM; - - codec->dev = &pdev->dev; - - mutex_init(&codec->mutex); - - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - codec->name = "spdif-dit"; - codec->owner = THIS_MODULE; - codec->dai = &dit_stub_dai; - codec->num_dai = 1; - - spdif_dit_codec = codec; - - ret = snd_soc_register_codec(codec); - if (ret < 0) { - dev_err(codec->dev, "Failed to register codec: %d\n", ret); - goto err_reg_codec; - } - - dit_stub_dai.dev = &pdev->dev; - ret = snd_soc_register_dai(&dit_stub_dai); - if (ret < 0) { - dev_err(codec->dev, "Failed to register dai: %d\n", ret); - goto err_reg_dai; - } - - return 0; - -err_reg_dai: - snd_soc_unregister_codec(codec); -err_reg_codec: - kfree(spdif_dit_codec); - return ret; + return snd_soc_register_codec(&pdev->dev, pdev->id, &soc_codec_spdif_dit, + &dit_stub_dai, 1); }
static int spdif_dit_remove(struct platform_device *pdev) { - snd_soc_unregister_dai(&dit_stub_dai); - snd_soc_unregister_codec(spdif_dit_codec); - kfree(spdif_dit_codec); - spdif_dit_codec = NULL; + snd_soc_unregister_codec(&pdev->dev, pdev->id); return 0; }
diff --git a/sound/soc/codecs/spdif_transciever.h b/sound/soc/codecs/spdif_transciever.h index 1e10212..17e2de8 100644 --- a/sound/soc/codecs/spdif_transciever.h +++ b/sound/soc/codecs/spdif_transciever.h @@ -12,7 +12,7 @@ #ifndef CODEC_STUBS_H #define CODEC_STUBS_H
-extern struct snd_soc_codec_device soc_codec_dev_spdif_dit; -extern struct snd_soc_dai dit_stub_dai; +extern struct snd_soc_codec_driver soc_codec_spdif_dit; +extern struct snd_soc_codec_driver dit_spdif_dr;
#endif /* CODEC_STUBS_H */
Move CODECs to multi-component model.
This patch changes the probe() and remove() of the CODEC drivers as follows:-
o Make CODEC driver a platform device (non MFD codecs only) o Moved all struct snd_soc_codec list, mutex, etc initialiasation to core. o Removed all static codec pointers (drivers now support > 1 codec dev) o snd_soc_register_pcms() now done by core. o snd_soc_register_dai() folded into snd_soc_register_codec(). o codec cache can now be malloc()ed by core.
Other required changes due to multi-component model :-
o cx20442: tty hangup now performed in codec remove() rather than machine remove() since codec device is not now available at machine remove().
Signed-off-by: Liam Girdwood lrg@slimlogic.co.uk --- sound/soc/codecs/cq93vc.c | 127 +++++++++----------------------------- sound/soc/codecs/cq93vc.h | 4 +- sound/soc/codecs/cx20442.c | 140 ++++++++++------------------------------- sound/soc/codecs/cx20442.h | 4 +- sound/soc/codecs/stac9766.c | 113 +++++++++++++++------------------ sound/soc/codecs/stac9766.h | 4 +- sound/soc/codecs/uda134x.c | 146 +++++++++++++++++-------------------------- sound/soc/codecs/uda134x.h | 4 +- 8 files changed, 178 insertions(+), 364 deletions(-)
diff --git a/sound/soc/codecs/cq93vc.c b/sound/soc/codecs/cq93vc.c index a320fb5..656869e 100644 --- a/sound/soc/codecs/cq93vc.c +++ b/sound/soc/codecs/cq93vc.c @@ -130,7 +130,7 @@ static struct snd_soc_dai_ops cq93vc_dai_ops = { .set_sysclk = cq93vc_set_dai_sysclk, };
-struct snd_soc_dai cq93vc_dai = { +struct snd_soc_dai_driver cq93vc_dai = { .name = "CQ93VC", .playback = { .stream_name = "Playback", @@ -148,34 +148,19 @@ struct snd_soc_dai cq93vc_dai = { }; EXPORT_SYMBOL_GPL(cq93vc_dai);
-static int cq93vc_resume(struct platform_device *pdev) +static int cq93vc_resume(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - cq93vc_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
return 0; }
-static struct snd_soc_codec *cq93vc_codec; - -static int cq93vc_probe(struct platform_device *pdev) +static int cq93vc_probe(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct device *dev = &pdev->dev; - struct snd_soc_codec *codec; - int ret; - - socdev->card->codec = cq93vc_codec; - codec = socdev->card->codec; - - /* Register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret < 0) { - dev_err(dev, "%s: failed to create pcms\n", pdev->name); - return ret; - } + struct davinci_vc *davinci_vc = codec->dev->platform_data; + + davinci_vc->cq93vc.codec = codec; + codec->control_data = davinci_vc;
/* Set controls */ snd_soc_add_controls(codec, cq93vc_snd_controls, @@ -187,108 +172,54 @@ static int cq93vc_probe(struct platform_device *pdev) return 0; }
-static int cq93vc_remove(struct platform_device *pdev) +static int cq93vc_remove(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - - snd_soc_free_pcms(socdev); - snd_soc_dapm_free(socdev); + cq93vc_set_bias_level(codec, SND_SOC_BIAS_OFF);
return 0; }
-struct snd_soc_codec_device soc_codec_dev_cq93vc = { +struct snd_soc_codec_driver soc_codec_dev_cq93vc = { + .name = "CQ93VC", + .owner = THIS_MODULE, + .read = cq93vc_read, + .write = cq93vc_write, + .set_bias_level = cq93vc_set_bias_level, .probe = cq93vc_probe, .remove = cq93vc_remove, .resume = cq93vc_resume, }; EXPORT_SYMBOL_GPL(soc_codec_dev_cq93vc);
-static __init int cq93vc_codec_probe(struct platform_device *pdev) +static int cq93vc_platform_probe(struct platform_device *pdev) { - struct davinci_vc *davinci_vc = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - int ret; - - codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); - if (codec == NULL) { - dev_dbg(davinci_vc->dev, - "could not allocate memory for codec data\n"); - return -ENOMEM; - } - - davinci_vc->cq93vc.codec = codec; - - cq93vc_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 = "CQ93VC"; - codec->owner = THIS_MODULE; - codec->read = cq93vc_read; - codec->write = cq93vc_write; - codec->set_bias_level = cq93vc_set_bias_level; - codec->dai = &cq93vc_dai; - codec->num_dai = 1; - codec->control_data = davinci_vc; - - cq93vc_codec = codec; - - ret = snd_soc_register_codec(codec); - if (ret) { - dev_err(davinci_vc->dev, "failed to register codec\n"); - goto fail1; - } - - ret = snd_soc_register_dai(&cq93vc_dai); - if (ret) { - dev_err(davinci_vc->dev, "could register dai\n"); - goto fail2; - } - return 0; - -fail2: - snd_soc_unregister_codec(codec); - -fail1: - kfree(codec); - cq93vc_codec = NULL; - - return ret; + return snd_soc_register_codec(&pdev->dev, pdev->id, + &soc_codec_dev_cq93vc, &cq93vc_dai, 1); }
-static int __devexit cq93vc_codec_remove(struct platform_device *pdev) +static int cq93vc_platform_remove(struct platform_device *pdev) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - - snd_soc_unregister_dai(&cq93vc_dai); - snd_soc_unregister_codec(&codec); - - kfree(codec); - cq93vc_codec = NULL; - + snd_soc_unregister_codec(&pdev->dev, pdev->id); return 0; }
static struct platform_driver cq93vc_codec_driver = { .driver = { - .name = "cq93vc", - .owner = THIS_MODULE, - }, - .probe = cq93vc_codec_probe, - .remove = __devexit_p(cq93vc_codec_remove), + .name = "cq93vc", + .owner = THIS_MODULE, + }, + + .probe = cq93vc_platform_probe, + .remove = __devexit_p(cq93vc_platform_remove), };
-static __init int cq93vc_init(void) +static int __init cq93vc_init(void) { - return platform_driver_probe(&cq93vc_codec_driver, cq93vc_codec_probe); + return platform_driver_register(&cq93vc_codec_driver); } module_init(cq93vc_init);
-static __exit void cq93vc_exit(void) +static void __exit cq93vc_exit(void) { platform_driver_unregister(&cq93vc_codec_driver); } diff --git a/sound/soc/codecs/cq93vc.h b/sound/soc/codecs/cq93vc.h index 845b196..77f9d3d 100644 --- a/sound/soc/codecs/cq93vc.h +++ b/sound/soc/codecs/cq93vc.h @@ -23,7 +23,7 @@ #ifndef _CQ93VC_H #define _CQ93VC_H
-extern struct snd_soc_dai cq93vc_dai; -extern struct snd_soc_codec_device soc_codec_dev_cq93vc; +extern struct snd_soc_dai_driver cq93vc_dai; +extern struct snd_soc_codec_driver soc_codec_dev_cq93vc;
#endif diff --git a/sound/soc/codecs/cx20442.c b/sound/soc/codecs/cx20442.c index f07a415..5285452 100644 --- a/sound/soc/codecs/cx20442.c +++ b/sound/soc/codecs/cx20442.c @@ -24,7 +24,8 @@
struct cx20442_priv { - struct snd_soc_codec codec; + enum snd_soc_control_type control_type; + void *control_data; u8 reg_cache[1]; };
@@ -102,7 +103,7 @@ static unsigned int cx20442_read_reg_cache(struct snd_soc_codec *codec, { u8 *reg_cache = codec->reg_cache;
- if (reg >= codec->reg_cache_size) + if (reg >= codec->driver->reg_cache_size) return -EINVAL;
return reg_cache[reg]; @@ -168,7 +169,7 @@ static int cx20442_write(struct snd_soc_codec *codec, unsigned int reg, int vls, vsp, old, len; char buf[18];
- if (reg >= codec->reg_cache_size) + if (reg >= codec->driver->reg_cache_size) return -EINVAL;
/* hw_write and control_data pointers required for talking to the modem @@ -313,7 +314,7 @@ EXPORT_SYMBOL_GPL(v253_ops); * Codec DAI */
-struct snd_soc_dai cx20442_dai = { +struct snd_soc_dai_driver cx20442_dai = { .name = "CX20442", .playback = { .stream_name = "Playback", @@ -332,134 +333,59 @@ struct snd_soc_dai cx20442_dai = { }; EXPORT_SYMBOL_GPL(cx20442_dai);
-static int cx20442_codec_probe(struct platform_device *pdev) +static int cx20442_codec_probe(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - int ret; - - if (!cx20442_codec) { - dev_err(&pdev->dev, "cx20442 not yet discovered\n"); - return -ENODEV; - } - codec = cx20442_codec; - - socdev->card->codec = codec; + struct cx20442_priv *cx20442;
- /* register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret < 0) { - dev_err(&pdev->dev, "failed to create pcms\n"); - goto pcm_err; - } + cx20442 = kzalloc(sizeof(struct cx20442_priv), GFP_KERNEL); + if (cx20442 == NULL) + return -ENOMEM; + snd_soc_codec_set_drvdata(codec, cx20442);
cx20442_add_widgets(codec);
-pcm_err: - return ret; + codec->control_data = NULL; + codec->hw_write = NULL; + codec->pop_time = 0; + + return 0; }
/* power down chip */ -static int cx20442_codec_remove(struct platform_device *pdev) +static int cx20442_codec_remove(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); + struct cx20442_priv *cx20442 = snd_soc_codec_get_drvdata(codec);
- snd_soc_free_pcms(socdev); - snd_soc_dapm_free(socdev); + if (codec->control_data) { + struct tty_struct *tty = codec->control_data; + tty_hangup(tty); + }
+ kfree(cx20442); return 0; }
-struct snd_soc_codec_device cx20442_codec_dev = { +struct snd_soc_codec_driver cx20442_codec_dev = { + .name = "CX20442", + .owner = THIS_MODULE, .probe = cx20442_codec_probe, .remove = cx20442_codec_remove, + .reg_cache_size = 1, + .reg_word_size = sizeof(u8), + .read = cx20442_read_reg_cache, + .write = cx20442_write, }; EXPORT_SYMBOL_GPL(cx20442_codec_dev);
-static int cx20442_register(struct cx20442_priv *cx20442) -{ - struct snd_soc_codec *codec = &cx20442->codec; - int ret; - - mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - codec->name = "CX20442"; - codec->owner = THIS_MODULE; - snd_soc_codec_set_drvdata(codec, cx20442); - - codec->dai = &cx20442_dai; - codec->num_dai = 1; - - codec->reg_cache = &cx20442->reg_cache; - codec->reg_cache_size = ARRAY_SIZE(cx20442->reg_cache); - codec->read = cx20442_read_reg_cache; - codec->write = cx20442_write; - - codec->bias_level = SND_SOC_BIAS_OFF; - - cx20442_dai.dev = codec->dev; - - cx20442_codec = codec; - - ret = snd_soc_register_codec(codec); - if (ret != 0) { - dev_err(codec->dev, "Failed to register codec: %d\n", ret); - goto err; - } - - ret = snd_soc_register_dai(&cx20442_dai); - if (ret != 0) { - dev_err(codec->dev, "Failed to register DAI: %d\n", ret); - goto err_codec; - } - - return 0; - -err_codec: - snd_soc_unregister_codec(codec); -err: - cx20442_codec = NULL; - kfree(cx20442); - return ret; -} - -static void cx20442_unregister(struct cx20442_priv *cx20442) -{ - snd_soc_unregister_dai(&cx20442_dai); - snd_soc_unregister_codec(&cx20442->codec); - - cx20442_codec = NULL; - kfree(cx20442); -} - static int cx20442_platform_probe(struct platform_device *pdev) { - struct cx20442_priv *cx20442; - struct snd_soc_codec *codec; - - cx20442 = kzalloc(sizeof(struct cx20442_priv), GFP_KERNEL); - if (cx20442 == NULL) - return -ENOMEM; - - codec = &cx20442->codec; - - codec->control_data = NULL; - codec->hw_write = NULL; - codec->pop_time = 0; - - codec->dev = &pdev->dev; - platform_set_drvdata(pdev, cx20442); - - return cx20442_register(cx20442); + return snd_soc_register_codec(&pdev->dev, pdev->id, + &cx20442_codec_dev, &cx20442_dai, 1); }
static int __exit cx20442_platform_remove(struct platform_device *pdev) { - struct cx20442_priv *cx20442 = platform_get_drvdata(pdev); - - cx20442_unregister(cx20442); + snd_soc_unregister_codec(&pdev->dev, pdev->id); return 0; }
diff --git a/sound/soc/codecs/cx20442.h b/sound/soc/codecs/cx20442.h index 688a5eb..e37e1c7 100644 --- a/sound/soc/codecs/cx20442.h +++ b/sound/soc/codecs/cx20442.h @@ -13,8 +13,8 @@ #ifndef _CX20442_CODEC_H #define _CX20442_CODEC_H
-extern struct snd_soc_dai cx20442_dai; -extern struct snd_soc_codec_device cx20442_codec_dev; +extern struct snd_soc_dai_driver cx20442_dai; +extern struct snd_soc_codec_driver cx20442_codec_dev; extern struct tty_ldisc_ops v253_ops;
#endif diff --git a/sound/soc/codecs/stac9766.c b/sound/soc/codecs/stac9766.c index ee86568..82b10fb 100644 --- a/sound/soc/codecs/stac9766.c +++ b/sound/soc/codecs/stac9766.c @@ -257,20 +257,15 @@ static int stac9766_reset(struct snd_soc_codec *codec, int try_warm) return 0; }
-static int stac9766_codec_suspend(struct platform_device *pdev, +static int stac9766_codec_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; - stac9766_set_bias_level(codec, SND_SOC_BIAS_OFF); return 0; }
-static int stac9766_codec_resume(struct platform_device *pdev) +static int stac9766_codec_resume(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; u16 id, reset;
reset = 0; @@ -300,10 +295,9 @@ static struct snd_soc_dai_ops stac9766_dai_ops_digital = { .prepare = ac97_digital_prepare, };
-struct snd_soc_dai stac9766_dai[] = { +struct snd_soc_dai_driver stac9766_dai[] = { { .name = "stac9766 analog", - .id = 0, .ac97_control = 1,
/* stream cababilities */ @@ -326,7 +320,6 @@ struct snd_soc_dai stac9766_dai[] = { }, { .name = "stac9766 IEC958", - .id = 1, .ac97_control = 1,
/* stream cababilities */ @@ -344,55 +337,23 @@ struct snd_soc_dai stac9766_dai[] = { }; EXPORT_SYMBOL_GPL(stac9766_dai);
-static int stac9766_codec_probe(struct platform_device *pdev) +static int stac9766_codec_probe(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; int ret = 0;
printk(KERN_INFO "STAC9766 SoC Audio Codec %s\n", STAC9766_VERSION);
- socdev->card->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); - if (socdev->card->codec == NULL) - return -ENOMEM; - codec = socdev->card->codec; - mutex_init(&codec->mutex); - - codec->reg_cache = kmemdup(stac9766_reg, sizeof(stac9766_reg), - GFP_KERNEL); - if (codec->reg_cache == NULL) { - ret = -ENOMEM; - goto cache_err; - } - codec->reg_cache_size = sizeof(stac9766_reg); - codec->reg_cache_step = 2; - - codec->name = "STAC9766"; - codec->owner = THIS_MODULE; - codec->dai = stac9766_dai; - codec->num_dai = ARRAY_SIZE(stac9766_dai); - codec->write = stac9766_ac97_write; - codec->read = stac9766_ac97_read; - codec->set_bias_level = stac9766_set_bias_level; - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - ret = snd_soc_new_ac97_codec(codec, &soc_ac97_ops, 0); if (ret < 0) goto codec_err;
- /* register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret < 0) - goto pcm_err; - /* do a cold reset for the controller and then try * a warm reset followed by an optional cold reset for codec */ stac9766_reset(codec, 0); ret = stac9766_reset(codec, 1); if (ret < 0) { printk(KERN_ERR "Failed to reset STAC9766: AC97 link error\n"); - goto reset_err; + goto codec_err; }
stac9766_set_bias_level(codec, SND_SOC_BIAS_STANDBY); @@ -402,41 +363,67 @@ static int stac9766_codec_probe(struct platform_device *pdev)
return 0;
-reset_err: - snd_soc_free_pcms(socdev); -pcm_err: - snd_soc_free_ac97_codec(codec); codec_err: - kfree(snd_soc_codec_get_drvdata(codec)); -cache_err: - kfree(socdev->card->codec); - socdev->card->codec = NULL; + snd_soc_free_ac97_codec(codec); return ret; }
-static int stac9766_codec_remove(struct platform_device *pdev) +static int stac9766_codec_remove(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - - if (codec == NULL) - return 0; - - snd_soc_free_pcms(socdev); snd_soc_free_ac97_codec(codec); - kfree(codec->reg_cache); - kfree(codec); return 0; }
-struct snd_soc_codec_device soc_codec_dev_stac9766 = { +struct snd_soc_codec_driver soc_codec_dev_stac9766 = { + .name = "STAC9766", + .owner = THIS_MODULE, + .write = stac9766_ac97_write, + .read = stac9766_ac97_read, + .set_bias_level = stac9766_set_bias_level, .probe = stac9766_codec_probe, .remove = stac9766_codec_remove, .suspend = stac9766_codec_suspend, .resume = stac9766_codec_resume, + .reg_cache_size = sizeof(stac9766_reg), + .reg_word_size = sizeof(u16), + .reg_cache_step = 2, }; EXPORT_SYMBOL_GPL(soc_codec_dev_stac9766);
+static __devinit int stac9766_probe(struct platform_device *pdev) +{ + return snd_soc_register_codec(&pdev->dev, pdev->id, + &soc_codec_dev_stac9766, stac9766_dai, ARRAY_SIZE(stac9766_dai)); +} + +static int __devexit stac9766_remove(struct platform_device *pdev) +{ + snd_soc_unregister_codec(&pdev->dev, pdev->id); + return 0; +} + +static struct platform_driver stac9766_codec_driver = { + .driver = { + .name = "stac9766-audio", + .owner = THIS_MODULE, + }, + + .probe = stac9766_probe, + .remove = __devexit_p(stac9766_remove), +}; + +static int __init stac9766_init(void) +{ + return platform_driver_register(&stac9766_codec_driver); +} +module_init(stac9766_init); + +static void __exit stac9766_exit(void) +{ + platform_driver_unregister(&stac9766_codec_driver); +} +module_exit(stac9766_exit); + MODULE_DESCRIPTION("ASoC stac9766 driver"); MODULE_AUTHOR("Jon Smirl jonsmirl@gmail.com"); MODULE_LICENSE("GPL"); diff --git a/sound/soc/codecs/stac9766.h b/sound/soc/codecs/stac9766.h index 65642eb..c387124 100644 --- a/sound/soc/codecs/stac9766.h +++ b/sound/soc/codecs/stac9766.h @@ -14,8 +14,8 @@ #define STAC9766_DAI_AC97_ANALOG 0 #define STAC9766_DAI_AC97_DIGITAL 1
-extern struct snd_soc_dai stac9766_dai[]; -extern struct snd_soc_codec_device soc_codec_dev_stac9766; +extern struct snd_soc_dai_driver stac9766_dai[]; +extern struct snd_soc_codec_driver soc_codec_dev_stac9766;
#endif diff --git a/sound/soc/codecs/uda134x.c b/sound/soc/codecs/uda134x.c index 28aac53..b6a64b5 100644 --- a/sound/soc/codecs/uda134x.c +++ b/sound/soc/codecs/uda134x.c @@ -173,8 +173,7 @@ static int uda134x_startup(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 uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec); struct snd_pcm_runtime *master_runtime;
@@ -206,8 +205,7 @@ static void uda134x_shutdown(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 uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
if (uda134x->master_substream == substream) @@ -221,8 +219,7 @@ static int uda134x_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 uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec); u8 hw_params;
@@ -362,7 +359,7 @@ static int uda134x_set_bias_level(struct snd_soc_codec *codec, pd->power(1); /* Sync reg_cache with the hardware */ for (i = 0; i < ARRAY_SIZE(uda134x_reg); i++) - codec->write(codec, i, *cache++); + codec->driver->write(codec, i, *cache++); } break; case SND_SOC_BIAS_STANDBY: @@ -449,7 +446,7 @@ static struct snd_soc_dai_ops uda134x_dai_ops = { .set_fmt = uda134x_set_dai_fmt, };
-struct snd_soc_dai uda134x_dai = { +struct snd_soc_dai_driver uda134x_dai = { .name = "UDA134X", /* playback capabilities */ .playback = { @@ -473,24 +470,20 @@ struct snd_soc_dai uda134x_dai = { EXPORT_SYMBOL(uda134x_dai);
-static int uda134x_soc_probe(struct platform_device *pdev) +static int uda134x_soc_probe(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; struct uda134x_priv *uda134x; - void *codec_setup_data = socdev->codec_data; - int ret = -ENOMEM; - struct uda134x_platform_data *pd; + struct uda134x_platform_data *pd = dev_get_drvdata(codec->card->dev); + int ret;
printk(KERN_INFO "UDA134X SoC Audio Codec\n");
- if (!codec_setup_data) { + if (!pd) { printk(KERN_ERR "UDA134X SoC codec: " "missing L3 bitbang function\n"); return -ENODEV; }
- pd = codec_setup_data; switch (pd->model) { case UDA134X_UDA1340: case UDA134X_UDA1341: @@ -504,53 +497,18 @@ static int uda134x_soc_probe(struct platform_device *pdev) return -EINVAL; }
- socdev->card->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); - if (socdev->card->codec == NULL) - return ret; - - codec = socdev->card->codec; - uda134x = kzalloc(sizeof(struct uda134x_priv), GFP_KERNEL); if (uda134x == NULL) - goto priv_err; + return -ENOMEM; snd_soc_codec_set_drvdata(codec, uda134x);
- codec->reg_cache = kmemdup(uda134x_reg, sizeof(uda134x_reg), - GFP_KERNEL); - if (codec->reg_cache == NULL) - goto reg_err; - - mutex_init(&codec->mutex); - - codec->reg_cache_size = sizeof(uda134x_reg); - codec->reg_cache_step = 1; - - codec->name = "UDA134X"; - codec->owner = THIS_MODULE; - codec->dai = &uda134x_dai; - codec->num_dai = 1; - codec->read = uda134x_read_reg_cache; - codec->write = uda134x_write; -#ifdef POWER_OFF_ON_STANDBY - codec->set_bias_level = uda134x_set_bias_level; -#endif - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - codec->control_data = codec_setup_data; + codec->control_data = pd;
if (pd->power) pd->power(1);
uda134x_reset(codec);
- /* register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret < 0) { - printk(KERN_ERR "UDA134X: failed to register pcms\n"); - goto pcm_err; - } - switch (pd->model) { case UDA134X_UDA1340: case UDA134X_UDA1344: @@ -568,61 +526,42 @@ static int uda134x_soc_probe(struct platform_device *pdev) default: printk(KERN_ERR "%s unknown codec type: %d", __func__, pd->model); - return -EINVAL; + kfree(uda134x); + return -EINVAL; }
if (ret < 0) { printk(KERN_ERR "UDA134X: failed to register controls\n"); - goto pcm_err; + kfree(uda134x); + return ret; }
return 0; - -pcm_err: - kfree(codec->reg_cache); -reg_err: - kfree(snd_soc_codec_get_drvdata(codec)); -priv_err: - kfree(codec); - return ret; }
/* power down chip */ -static int uda134x_soc_remove(struct platform_device *pdev) +static int uda134x_soc_remove(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; + struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
uda134x_set_bias_level(codec, SND_SOC_BIAS_STANDBY); uda134x_set_bias_level(codec, SND_SOC_BIAS_OFF);
- snd_soc_free_pcms(socdev); - snd_soc_dapm_free(socdev); - - kfree(snd_soc_codec_get_drvdata(codec)); - kfree(codec->reg_cache); - kfree(codec); - + kfree(uda134x); return 0; }
#if defined(CONFIG_PM) -static int uda134x_soc_suspend(struct platform_device *pdev, +static int uda134x_soc_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; - uda134x_set_bias_level(codec, SND_SOC_BIAS_STANDBY); uda134x_set_bias_level(codec, SND_SOC_BIAS_OFF); return 0; }
-static int uda134x_soc_resume(struct platform_device *pdev) +static int uda134x_soc_resume(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - uda134x_set_bias_level(codec, SND_SOC_BIAS_PREPARE); uda134x_set_bias_level(codec, SND_SOC_BIAS_ON); return 0; @@ -632,25 +571,56 @@ static int uda134x_soc_resume(struct platform_device *pdev) #define uda134x_soc_resume NULL #endif /* CONFIG_PM */
-struct snd_soc_codec_device soc_codec_dev_uda134x = { +struct snd_soc_codec_driver soc_codec_dev_uda134x = { + .name = "UDA134X", + .owner = THIS_MODULE, .probe = uda134x_soc_probe, .remove = uda134x_soc_remove, .suspend = uda134x_soc_suspend, .resume = uda134x_soc_resume, + .reg_cache_size = sizeof(uda134x_reg), + .reg_word_size = sizeof(u8), + .reg_cache_step = 1, + .read = uda134x_read_reg_cache, + .write = uda134x_write, +#ifdef POWER_OFF_ON_STANDBY + .set_bias_level = uda134x_set_bias_level, +#endif }; EXPORT_SYMBOL_GPL(soc_codec_dev_uda134x);
-static int __init uda134x_init(void) +static int __devinit uda134x_codec_probe(struct platform_device *pdev) +{ + return snd_soc_register_codec(&pdev->dev, pdev->id, + &soc_codec_dev_uda134x, &uda134x_dai, 1); +} + +static int __devexit uda134x_codec_remove(struct platform_device *pdev) +{ + snd_soc_unregister_codec(&pdev->dev, pdev->id); + return 0; +} + +static struct platform_driver uda134x_codec_driver = { + .driver = { + .name = "uda134x_codec", + .owner = THIS_MODULE, + }, + .probe = uda134x_codec_probe, + .remove = __devexit_p(uda134x_codec_remove), +}; + +static int __init uda134x_codec_init(void) { - return snd_soc_register_dai(&uda134x_dai); + return platform_driver_register(&uda134x_codec_driver); } -module_init(uda134x_init); +module_init(uda134x_codec_init);
-static void __exit uda134x_exit(void) +static void __exit uda134x_codec_exit(void) { - snd_soc_unregister_dai(&uda134x_dai); + platform_driver_unregister(&uda134x_codec_driver); } -module_exit(uda134x_exit); +module_exit(uda134x_codec_exit);
MODULE_DESCRIPTION("UDA134X ALSA soc codec driver"); MODULE_AUTHOR("Zoltan Devai, Christian Pellegrin chripell@evolware.org"); diff --git a/sound/soc/codecs/uda134x.h b/sound/soc/codecs/uda134x.h index 94f4404..0585cde 100644 --- a/sound/soc/codecs/uda134x.h +++ b/sound/soc/codecs/uda134x.h @@ -30,7 +30,7 @@ #define STATUS0_DAIFMT_MASK (~(7<<1)) #define STATUS0_SYSCLK_MASK (~(3<<4))
-extern struct snd_soc_dai uda134x_dai; -extern struct snd_soc_codec_device soc_codec_dev_uda134x; +extern struct snd_soc_dai_driver uda134x_dai; +extern struct snd_soc_codec_driver soc_codec_dev_uda134x;
#endif
Moved Wolfson WM85xx CODECs to multi-component model
This patch changes the probe() and remove() of the CODEC drivers as follows:-
o Make CODEC driver a platform device (non MFD codecs only) o Moved all struct snd_soc_codec list, mutex, etc initialiasation to core. o Removed all static codec pointers (drivers now support > 1 codec dev) o snd_soc_register_pcms() now done by core. o snd_soc_register_dai() folded into snd_soc_register_codec(). o codec cache can now be malloc()ed by core.
Signed-off-by: Liam Girdwood lrg@slimlogic.co.uk --- sound/soc/codecs/wm8510.c | 290 ++++++++++++++++----------------------------- sound/soc/codecs/wm8510.h | 4 +- sound/soc/codecs/wm8523.c | 176 ++++++++-------------------- sound/soc/codecs/wm8523.h | 4 +- sound/soc/codecs/wm8580.c | 168 +++++++------------------- sound/soc/codecs/wm8580.h | 4 +- 6 files changed, 200 insertions(+), 446 deletions(-)
diff --git a/sound/soc/codecs/wm8510.c b/sound/soc/codecs/wm8510.c index 0f7bcb6..c8b5fd8 100644 --- a/sound/soc/codecs/wm8510.c +++ b/sound/soc/codecs/wm8510.c @@ -31,8 +31,6 @@
#define WM8510_VERSION "0.6"
-struct snd_soc_codec_device soc_codec_dev_wm8510; - /* * wm8510 register cache * We can't read the WM8510 register space when we are @@ -61,6 +59,12 @@ static const u16 wm8510_reg[WM8510_CACHEREGNUM] = {
#define wm8510_reset(c) snd_soc_write(c, WM8510_RESET, 0)
+/* codec private data */ +struct wm8510_priv { + enum snd_soc_control_type control_type; + void *control_data; +}; + static const char *wm8510_companding[] = { "Off", "NC", "u-law", "A-law" }; static const char *wm8510_deemp[] = { "None", "32kHz", "44.1kHz", "48kHz" }; static const char *wm8510_alc[] = { "ALC", "Limiter" }; @@ -403,8 +407,7 @@ static int wm8510_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; u16 iface = snd_soc_read(codec, WM8510_IFACE) & 0x19f; u16 adn = snd_soc_read(codec, WM8510_ADD) & 0x1f1;
@@ -514,7 +517,7 @@ static struct snd_soc_dai_ops wm8510_dai_ops = { .set_pll = wm8510_set_dai_pll, };
-struct snd_soc_dai wm8510_dai = { +struct snd_soc_dai_driver wm8510_dai = { .name = "WM8510 HiFi", .playback = { .stream_name = "Playback", @@ -533,19 +536,14 @@ struct snd_soc_dai wm8510_dai = { }; EXPORT_SYMBOL_GPL(wm8510_dai);
-static int wm8510_suspend(struct platform_device *pdev, pm_message_t state) +static int wm8510_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; - wm8510_set_bias_level(codec, SND_SOC_BIAS_OFF); return 0; }
-static int wm8510_resume(struct platform_device *pdev) +static int wm8510_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; @@ -561,43 +559,22 @@ static int wm8510_resume(struct platform_device *pdev) return 0; }
-/* - * initialise the WM8510 driver - * register the mixer and dsp interfaces with the kernel - */ -static int wm8510_init(struct snd_soc_device *socdev, - enum snd_soc_control_type control) +static int wm8510_probe(struct snd_soc_codec *codec) { - struct snd_soc_codec *codec = socdev->card->codec; - int ret = 0; - - codec->name = "WM8510"; - codec->owner = THIS_MODULE; - codec->set_bias_level = wm8510_set_bias_level; - codec->dai = &wm8510_dai; - codec->num_dai = 1; - codec->reg_cache_size = ARRAY_SIZE(wm8510_reg); - codec->reg_cache = kmemdup(wm8510_reg, sizeof(wm8510_reg), GFP_KERNEL); + struct wm8510_priv *wm8510 = snd_soc_codec_get_drvdata(codec); + int ret;
- if (codec->reg_cache == NULL) - return -ENOMEM; + pr_info("WM8510 Audio Codec %s", WM8510_VERSION);
- ret = snd_soc_codec_set_cache_io(codec, 7, 9, control); + codec->control_data = wm8510->control_data; + ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8510->control_type); if (ret < 0) { - printk(KERN_ERR "wm8510: failed to set cache I/O: %d\n", - ret); - goto err; + printk(KERN_ERR "wm8510: failed to set cache I/O: %d\n", ret); + return ret; }
wm8510_reset(codec);
- /* register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret < 0) { - printk(KERN_ERR "wm8510: failed to create pcms\n"); - goto err; - } - /* power on device */ codec->bias_level = SND_SOC_BIAS_OFF; wm8510_set_bias_level(codec, SND_SOC_BIAS_STANDBY); @@ -606,119 +583,56 @@ static int wm8510_init(struct snd_soc_device *socdev, wm8510_add_widgets(codec);
return ret; - -err: - kfree(codec->reg_cache); - return ret; }
-static struct snd_soc_device *wm8510_socdev; - -#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) - -/* - * WM8510 2 wire address is 0x1a - */ - -static int wm8510_i2c_probe(struct i2c_client *i2c, - const struct i2c_device_id *id) +/* power down chip */ +static int wm8510_remove(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = wm8510_socdev; - struct snd_soc_codec *codec = socdev->card->codec; - int ret; + struct wm8510_priv *wm8510 = snd_soc_codec_get_drvdata(codec);
- i2c_set_clientdata(i2c, codec); - codec->control_data = i2c; - - ret = wm8510_init(socdev, SND_SOC_I2C); - if (ret < 0) - pr_err("failed to initialise WM8510\n"); - - return ret; -} - -static int wm8510_i2c_remove(struct i2c_client *client) -{ - struct snd_soc_codec *codec = i2c_get_clientdata(client); - kfree(codec->reg_cache); + wm8510_set_bias_level(codec, SND_SOC_BIAS_OFF); + kfree(wm8510); return 0; }
-static const struct i2c_device_id wm8510_i2c_id[] = { - { "wm8510", 0 }, - { } -}; -MODULE_DEVICE_TABLE(i2c, wm8510_i2c_id); - -static struct i2c_driver wm8510_i2c_driver = { - .driver = { - .name = "WM8510 I2C Codec", - .owner = THIS_MODULE, - }, - .probe = wm8510_i2c_probe, - .remove = wm8510_i2c_remove, - .id_table = wm8510_i2c_id, +struct snd_soc_codec_driver soc_codec_dev_wm8510 = { + .name = "WM8510", + .owner = THIS_MODULE, + .probe = wm8510_probe, + .remove = wm8510_remove, + .suspend = wm8510_suspend, + .resume = wm8510_resume, + .set_bias_level = wm8510_set_bias_level, + .reg_cache_size = ARRAY_SIZE(wm8510_reg), + .reg_word_size = sizeof(u16), + .reg_cache_default =wm8510_reg, }; - -static int wm8510_add_i2c_device(struct platform_device *pdev, - const struct wm8510_setup_data *setup) -{ - struct i2c_board_info info; - struct i2c_adapter *adapter; - struct i2c_client *client; - int ret; - - ret = i2c_add_driver(&wm8510_i2c_driver); - if (ret != 0) { - dev_err(&pdev->dev, "can't add i2c driver\n"); - return ret; - } - - memset(&info, 0, sizeof(struct i2c_board_info)); - info.addr = setup->i2c_address; - strlcpy(info.type, "wm8510", I2C_NAME_SIZE); - - adapter = i2c_get_adapter(setup->i2c_bus); - if (!adapter) { - dev_err(&pdev->dev, "can't get i2c adapter %d\n", - setup->i2c_bus); - goto err_driver; - } - - client = i2c_new_device(adapter, &info); - i2c_put_adapter(adapter); - if (!client) { - dev_err(&pdev->dev, "can't add i2c device at 0x%x\n", - (unsigned int)info.addr); - goto err_driver; - } - - return 0; - -err_driver: - i2c_del_driver(&wm8510_i2c_driver); - return -ENODEV; -} -#endif +EXPORT_SYMBOL_GPL(soc_codec_dev_wm8510);
#if defined(CONFIG_SPI_MASTER) static int __devinit wm8510_spi_probe(struct spi_device *spi) { - struct snd_soc_device *socdev = wm8510_socdev; - struct snd_soc_codec *codec = socdev->card->codec; + struct wm8510_priv *wm8510; int ret;
- codec->control_data = spi; + wm8510 = kzalloc(sizeof(struct wm8510_priv), GFP_KERNEL); + if (wm8510 == NULL) + return -ENOMEM;
- ret = wm8510_init(socdev, SND_SOC_SPI); - if (ret < 0) - dev_err(&spi->dev, "failed to initialise WM8510\n"); + wm8510->control_data = spi; + wm8510->control_type = SND_SOC_SPI; + spi_set_drvdata(spi, wm8510);
+ ret = snd_soc_register_codec(&spi->dev, spi->chip_select, + &soc_codec_dev_wm8510, &wm8510_dai, 1); + if (ret < 0) + kfree(wm8510); return ret; }
static int __devexit wm8510_spi_remove(struct spi_device *spi) { + snd_soc_unregister_codec(&spi->dev, spi->chip_select); return 0; }
@@ -733,84 +647,80 @@ static struct spi_driver wm8510_spi_driver = { }; #endif /* CONFIG_SPI_MASTER */
-static int wm8510_probe(struct platform_device *pdev) +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) +static __devinit int wm8510_i2c_probe(struct i2c_client *i2c, + const struct i2c_device_id *id) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct wm8510_setup_data *setup; - struct snd_soc_codec *codec; - int ret = 0; - - pr_info("WM8510 Audio Codec %s", WM8510_VERSION); + struct wm8510_priv *wm8510; + int ret;
- setup = socdev->codec_data; - codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); - if (codec == NULL) + wm8510 = kzalloc(sizeof(struct wm8510_priv), GFP_KERNEL); + if (wm8510 == NULL) return -ENOMEM;
- socdev->card->codec = codec; - mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - wm8510_socdev = socdev; -#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) - if (setup->i2c_address) { - ret = wm8510_add_i2c_device(pdev, setup); - } -#endif -#if defined(CONFIG_SPI_MASTER) - if (setup->spi) { - ret = spi_register_driver(&wm8510_spi_driver); - if (ret != 0) - printk(KERN_ERR "can't add spi driver"); - } -#endif + i2c_set_clientdata(i2c, wm8510); + wm8510->control_data = i2c; + wm8510->control_type = SND_SOC_I2C;
- if (ret != 0) - kfree(codec); + ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &soc_codec_dev_wm8510, &wm8510_dai, 1); + if (ret < 0) + kfree(wm8510); return ret; }
-/* power down chip */ -static int wm8510_remove(struct platform_device *pdev) +static __devexit int wm8510_i2c_remove(struct i2c_client *client) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - - if (codec->control_data) - wm8510_set_bias_level(codec, SND_SOC_BIAS_OFF); - - snd_soc_free_pcms(socdev); - snd_soc_dapm_free(socdev); -#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) - i2c_unregister_device(codec->control_data); - i2c_del_driver(&wm8510_i2c_driver); -#endif -#if defined(CONFIG_SPI_MASTER) - spi_unregister_driver(&wm8510_spi_driver); -#endif - kfree(codec); - + snd_soc_unregister_codec(&client->dev, client->addr); return 0; }
-struct snd_soc_codec_device soc_codec_dev_wm8510 = { - .probe = wm8510_probe, - .remove = wm8510_remove, - .suspend = wm8510_suspend, - .resume = wm8510_resume, +static const struct i2c_device_id wm8510_i2c_id[] = { + { "wm8510", 0 }, + { } }; -EXPORT_SYMBOL_GPL(soc_codec_dev_wm8510); +MODULE_DEVICE_TABLE(i2c, wm8510_i2c_id); + +static struct i2c_driver wm8510_i2c_driver = { + .driver = { + .name = "WM8510 I2C Codec", + .owner = THIS_MODULE, + }, + .probe = wm8510_i2c_probe, + .remove = __devexit_p(wm8510_i2c_remove), + .id_table = wm8510_i2c_id, +}; +#endif
static int __init wm8510_modinit(void) { - return snd_soc_register_dai(&wm8510_dai); + int ret = 0; +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) + ret = i2c_add_driver(&wm8510_i2c_driver); + if (ret != 0) { + printk(KERN_ERR "Failed to register WM8510 I2C driver: %d\n", + ret); + } +#endif +#if defined(CONFIG_SPI_MASTER) + ret = spi_register_driver(&wm8510_spi_driver); + if (ret != 0) { + printk(KERN_ERR "Failed to register WM8510 SPI driver: %d\n", + ret); + } +#endif + return ret; } module_init(wm8510_modinit);
static void __exit wm8510_exit(void) { - snd_soc_unregister_dai(&wm8510_dai); +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) + i2c_del_driver(&wm8510_i2c_driver); +#endif +#if defined(CONFIG_SPI_MASTER) + spi_unregister_driver(&wm8510_spi_driver); +#endif } module_exit(wm8510_exit);
diff --git a/sound/soc/codecs/wm8510.h b/sound/soc/codecs/wm8510.h index bdefcf5..c3feb7a 100644 --- a/sound/soc/codecs/wm8510.h +++ b/sound/soc/codecs/wm8510.h @@ -99,7 +99,7 @@ struct wm8510_setup_data { unsigned short i2c_address; };
-extern struct snd_soc_dai wm8510_dai; -extern struct snd_soc_codec_device soc_codec_dev_wm8510; +extern struct snd_soc_dai_driver wm8510_dai; +extern struct snd_soc_codec_driver soc_codec_dev_wm8510;
#endif diff --git a/sound/soc/codecs/wm8523.c b/sound/soc/codecs/wm8523.c index 37242a7..32b9891 100644 --- a/sound/soc/codecs/wm8523.c +++ b/sound/soc/codecs/wm8523.c @@ -30,9 +30,6 @@
#include "wm8523.h"
-static struct snd_soc_codec *wm8523_codec; -struct snd_soc_codec_device soc_codec_dev_wm8523; - #define WM8523_NUM_SUPPLIES 2 static const char *wm8523_supply_names[WM8523_NUM_SUPPLIES] = { "AVDD", @@ -43,7 +40,8 @@ static const char *wm8523_supply_names[WM8523_NUM_SUPPLIES] = {
/* codec private data */ struct wm8523_priv { - struct snd_soc_codec codec; + enum snd_soc_control_type control_type; + void *control_data; u16 reg_cache[WM8523_REGISTER_COUNT]; struct regulator_bulk_data supplies[WM8523_NUM_SUPPLIES]; unsigned int sysclk; @@ -162,8 +160,7 @@ static int wm8523_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 wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec); int i; u16 aifctrl1 = snd_soc_read(codec, WM8523_AIF_CTRL1); @@ -387,7 +384,7 @@ static struct snd_soc_dai_ops wm8523_dai_ops = { .set_fmt = wm8523_set_dai_fmt, };
-struct snd_soc_dai wm8523_dai = { +struct snd_soc_dai_driver wm8523_dai = { .name = "WM8523", .playback = { .stream_name = "Playback", @@ -401,22 +398,15 @@ struct snd_soc_dai wm8523_dai = { EXPORT_SYMBOL_GPL(wm8523_dai);
#ifdef CONFIG_PM -static int wm8523_suspend(struct platform_device *pdev, pm_message_t state) +static int wm8523_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; - wm8523_set_bias_level(codec, SND_SOC_BIAS_OFF); return 0; }
-static int wm8523_resume(struct platform_device *pdev) +static int wm8523_resume(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - wm8523_set_bias_level(codec, SND_SOC_BIAS_STANDBY); - return 0; } #else @@ -424,92 +414,21 @@ static int wm8523_resume(struct platform_device *pdev) #define wm8523_resume NULL #endif
-static int wm8523_probe(struct platform_device *pdev) -{ - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - int ret = 0; - - if (wm8523_codec == NULL) { - dev_err(&pdev->dev, "Codec device not registered\n"); - return -ENODEV; - } - - socdev->card->codec = wm8523_codec; - codec = wm8523_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, wm8523_snd_controls, - ARRAY_SIZE(wm8523_snd_controls)); - wm8523_add_widgets(codec); - - return ret; - -pcm_err: - return ret; -} - -static int wm8523_remove(struct platform_device *pdev) +static int wm8523_probe(struct snd_soc_codec *codec) { - 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_wm8523 = { - .probe = wm8523_probe, - .remove = wm8523_remove, - .suspend = wm8523_suspend, - .resume = wm8523_resume, -}; -EXPORT_SYMBOL_GPL(soc_codec_dev_wm8523); - -static int wm8523_register(struct wm8523_priv *wm8523, - enum snd_soc_control_type control) -{ - int ret; - struct snd_soc_codec *codec = &wm8523->codec; - int i; - - if (wm8523_codec) { - dev_err(codec->dev, "Another WM8523 is registered\n"); - return -EINVAL; - } - - mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - snd_soc_codec_set_drvdata(codec, wm8523); - codec->name = "WM8523"; - codec->owner = THIS_MODULE; - codec->bias_level = SND_SOC_BIAS_OFF; - codec->set_bias_level = wm8523_set_bias_level; - codec->dai = &wm8523_dai; - codec->num_dai = 1; - codec->reg_cache_size = WM8523_REGISTER_COUNT; - codec->reg_cache = &wm8523->reg_cache; - codec->volatile_register = wm8523_volatile_register; + struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec); + int ret, i;
+ codec->hw_write = (hw_write_t)i2c_master_send; + codec->control_data = wm8523->control_data; wm8523->rate_constraint.list = &wm8523->rate_constraint_list[0]; wm8523->rate_constraint.count = ARRAY_SIZE(wm8523->rate_constraint_list);
- memcpy(codec->reg_cache, wm8523_reg, sizeof(wm8523_reg)); - - ret = snd_soc_codec_set_cache_io(codec, 8, 16, control); + ret = snd_soc_codec_set_cache_io(codec, 8, 16, wm8523->control_type); if (ret != 0) { dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); - goto err; + return ret; }
for (i = 0; i < ARRAY_SIZE(wm8523->supplies); i++) @@ -519,7 +438,7 @@ static int wm8523_register(struct wm8523_priv *wm8523, wm8523->supplies); if (ret != 0) { dev_err(codec->dev, "Failed to request supplies: %d\n", ret); - goto err; + return ret; }
ret = regulator_bulk_enable(ARRAY_SIZE(wm8523->supplies), @@ -554,8 +473,6 @@ static int wm8523_register(struct wm8523_priv *wm8523, goto err_enable; }
- wm8523_dai.dev = codec->dev; - /* Change some default settings - latch VU and enable ZC */ wm8523->reg_cache[WM8523_DAC_GAINR] |= WM8523_DACR_VU; wm8523->reg_cache[WM8523_DAC_CTRL3] |= WM8523_ZC; @@ -565,20 +482,9 @@ static int wm8523_register(struct wm8523_priv *wm8523, /* Bias level configuration will have done an extra enable */ regulator_bulk_disable(ARRAY_SIZE(wm8523->supplies), wm8523->supplies);
- wm8523_codec = codec; - - ret = snd_soc_register_codec(codec); - if (ret != 0) { - dev_err(codec->dev, "Failed to register codec: %d\n", ret); - return ret; - } - - ret = snd_soc_register_dai(&wm8523_dai); - if (ret != 0) { - dev_err(codec->dev, "Failed to register DAI: %d\n", ret); - snd_soc_unregister_codec(codec); - return ret; - } + snd_soc_add_controls(codec, wm8523_snd_controls, + ARRAY_SIZE(wm8523_snd_controls)); + wm8523_add_widgets(codec);
return 0;
@@ -586,47 +492,61 @@ err_enable: regulator_bulk_disable(ARRAY_SIZE(wm8523->supplies), wm8523->supplies); err_get: regulator_bulk_free(ARRAY_SIZE(wm8523->supplies), wm8523->supplies); -err: - kfree(wm8523); + return ret; }
-static void wm8523_unregister(struct wm8523_priv *wm8523) +static int wm8523_remove(struct snd_soc_codec *codec) { - wm8523_set_bias_level(&wm8523->codec, SND_SOC_BIAS_OFF); + struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec); + + wm8523_set_bias_level(codec, SND_SOC_BIAS_OFF); regulator_bulk_free(ARRAY_SIZE(wm8523->supplies), wm8523->supplies); - snd_soc_unregister_dai(&wm8523_dai); - snd_soc_unregister_codec(&wm8523->codec); - kfree(wm8523); - wm8523_codec = NULL; + return 0; }
+struct snd_soc_codec_driver soc_codec_dev_wm8523 = { + .name = "WM8523", + .owner = THIS_MODULE, + .probe = wm8523_probe, + .remove = wm8523_remove, + .suspend = wm8523_suspend, + .resume = wm8523_resume, + .set_bias_level = wm8523_set_bias_level, + .reg_cache_size = WM8523_REGISTER_COUNT, + .reg_word_size = sizeof(u16), + .reg_cache_default = wm8523_reg, + .volatile_register = wm8523_volatile_register, +}; +EXPORT_SYMBOL_GPL(soc_codec_dev_wm8523); + #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) static __devinit int wm8523_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct wm8523_priv *wm8523; - struct snd_soc_codec *codec; + int ret;
wm8523 = kzalloc(sizeof(struct wm8523_priv), GFP_KERNEL); if (wm8523 == NULL) return -ENOMEM;
- codec = &wm8523->codec; - codec->hw_write = (hw_write_t)i2c_master_send; - i2c_set_clientdata(i2c, wm8523); - codec->control_data = i2c; + wm8523->control_data = i2c; + wm8523->control_type = SND_SOC_I2C;
- codec->dev = &i2c->dev; + ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &soc_codec_dev_wm8523, &wm8523_dai, 1); + if (ret < 0) + kfree(wm8523); + return ret;
- return wm8523_register(wm8523, SND_SOC_I2C); }
static __devexit int wm8523_i2c_remove(struct i2c_client *client) { - struct wm8523_priv *wm8523 = i2c_get_clientdata(client); - wm8523_unregister(wm8523); + snd_soc_unregister_codec(&client->dev, client->addr); + kfree(i2c_get_clientdata(client)); return 0; }
diff --git a/sound/soc/codecs/wm8523.h b/sound/soc/codecs/wm8523.h index 1aa9ce3..80a1d85 100644 --- a/sound/soc/codecs/wm8523.h +++ b/sound/soc/codecs/wm8523.h @@ -154,7 +154,7 @@ #define WM8523_ZD_COUNT_SHIFT 0 /* ZD_COUNT - [1:0] */ #define WM8523_ZD_COUNT_WIDTH 2 /* ZD_COUNT - [1:0] */
-extern struct snd_soc_dai wm8523_dai; -extern struct snd_soc_codec_device soc_codec_dev_wm8523; +extern struct snd_soc_dai_driver wm8523_dai; +extern struct snd_soc_codec_driver soc_codec_dev_wm8523;
#endif diff --git a/sound/soc/codecs/wm8580.c b/sound/soc/codecs/wm8580.c index c3571ee..69dfc2c 100644 --- a/sound/soc/codecs/wm8580.c +++ b/sound/soc/codecs/wm8580.c @@ -199,7 +199,8 @@ static const char *wm8580_supply_names[WM8580_NUM_SUPPLIES] = {
/* codec private data */ struct wm8580_priv { - struct snd_soc_codec codec; + enum snd_soc_control_type control_type; + void *control_data; struct regulator_bulk_data supplies[WM8580_NUM_SUPPLIES]; u16 reg_cache[WM8580_MAX_REGISTER + 1]; struct pll_state a; @@ -484,8 +485,7 @@ static int wm8580_paif_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; u16 paifb = snd_soc_read(codec, WM8580_PAIF3 + dai->id);
paifb &= ~WM8580_AIF_LENGTH_MASK; @@ -746,10 +746,9 @@ static struct snd_soc_dai_ops wm8580_dai_ops_capture = { .set_pll = wm8580_set_dai_pll, };
-struct snd_soc_dai wm8580_dai[] = { +struct snd_soc_dai_driver wm8580_dai[] = { { .name = "WM8580 PAIFRX", - .id = 0, .playback = { .stream_name = "Playback", .channels_min = 1, @@ -761,7 +760,6 @@ struct snd_soc_dai wm8580_dai[] = { }, { .name = "WM8580 PAIFTX", - .id = 1, .capture = { .stream_name = "Capture", .channels_min = 2, @@ -774,88 +772,16 @@ struct snd_soc_dai wm8580_dai[] = { }; EXPORT_SYMBOL_GPL(wm8580_dai);
-static struct snd_soc_codec *wm8580_codec; - -static int wm8580_probe(struct platform_device *pdev) -{ - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - int ret = 0; - - if (wm8580_codec == NULL) { - dev_err(&pdev->dev, "Codec device not registered\n"); - return -ENODEV; - } - - socdev->card->codec = wm8580_codec; - codec = wm8580_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, wm8580_snd_controls, - ARRAY_SIZE(wm8580_snd_controls)); - wm8580_add_widgets(codec); - - return ret; - -pcm_err: - return ret; -} - -/* power down chip */ -static int wm8580_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_wm8580 = { - .probe = wm8580_probe, - .remove = wm8580_remove, -}; -EXPORT_SYMBOL_GPL(soc_codec_dev_wm8580); - -static int wm8580_register(struct wm8580_priv *wm8580, - enum snd_soc_control_type control) +static int wm8580_probe(struct snd_soc_codec *codec) { - int ret, i; - struct snd_soc_codec *codec = &wm8580->codec; - - if (wm8580_codec) { - dev_err(codec->dev, "Another WM8580 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, wm8580); - codec->name = "WM8580"; - codec->owner = THIS_MODULE; - codec->bias_level = SND_SOC_BIAS_OFF; - codec->set_bias_level = wm8580_set_bias_level; - codec->dai = wm8580_dai; - codec->num_dai = ARRAY_SIZE(wm8580_dai); - codec->reg_cache_size = ARRAY_SIZE(wm8580->reg_cache); - codec->reg_cache = &wm8580->reg_cache; - - memcpy(codec->reg_cache, wm8580_reg, sizeof(wm8580_reg)); + struct wm8580_priv *wm8580 = snd_soc_codec_get_drvdata(codec); + int ret = 0,i;
- ret = snd_soc_codec_set_cache_io(codec, 7, 9, control); + codec->control_data = wm8580->control_data; + ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8580->control_type); if (ret < 0) { dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); - goto err; + return ret; }
for (i = 0; i < ARRAY_SIZE(wm8580->supplies); i++) @@ -865,7 +791,7 @@ static int wm8580_register(struct wm8580_priv *wm8580, wm8580->supplies); if (ret != 0) { dev_err(codec->dev, "Failed to request supplies: %d\n", ret); - goto err; + return ret; }
ret = regulator_bulk_enable(ARRAY_SIZE(wm8580->supplies), @@ -882,74 +808,72 @@ static int wm8580_register(struct wm8580_priv *wm8580, goto err_regulator_enable; }
- for (i = 0; i < ARRAY_SIZE(wm8580_dai); i++) - wm8580_dai[i].dev = codec->dev; - wm8580_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
- wm8580_codec = codec; - - ret = snd_soc_register_codec(codec); - if (ret != 0) { - dev_err(codec->dev, "Failed to register codec: %d\n", ret); - goto err_regulator_enable; - } - - ret = snd_soc_register_dais(wm8580_dai, ARRAY_SIZE(wm8580_dai)); - if (ret != 0) { - dev_err(codec->dev, "Failed to register DAI: %d\n", ret); - goto err_codec; - } + snd_soc_add_controls(codec, wm8580_snd_controls, + ARRAY_SIZE(wm8580_snd_controls)); + wm8580_add_widgets(codec);
return 0;
-err_codec: - snd_soc_unregister_codec(codec); err_regulator_enable: regulator_bulk_disable(ARRAY_SIZE(wm8580->supplies), wm8580->supplies); err_regulator_get: regulator_bulk_free(ARRAY_SIZE(wm8580->supplies), wm8580->supplies); -err: - kfree(wm8580); return ret; }
-static void wm8580_unregister(struct wm8580_priv *wm8580) +/* power down chip */ +static int wm8580_remove(struct snd_soc_codec *codec) { - wm8580_set_bias_level(&wm8580->codec, SND_SOC_BIAS_OFF); - snd_soc_unregister_dais(wm8580_dai, ARRAY_SIZE(wm8580_dai)); - snd_soc_unregister_codec(&wm8580->codec); + struct wm8580_priv *wm8580 = snd_soc_codec_get_drvdata(codec); + + wm8580_set_bias_level(codec, SND_SOC_BIAS_OFF); + regulator_bulk_disable(ARRAY_SIZE(wm8580->supplies), wm8580->supplies); regulator_bulk_free(ARRAY_SIZE(wm8580->supplies), wm8580->supplies); - kfree(wm8580); - wm8580_codec = NULL; + + return 0; }
+struct snd_soc_codec_driver soc_codec_dev_wm8580 = { + .name = "WM8580", + .probe = wm8580_probe, + .remove = wm8580_remove, + .owner = THIS_MODULE, + .set_bias_level = wm8580_set_bias_level, + .reg_cache_size = sizeof(wm8580_reg), + .reg_word_size = sizeof(u16), + .reg_cache_default = &wm8580_reg, +}; +EXPORT_SYMBOL_GPL(soc_codec_dev_wm8580); + #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) static int wm8580_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct wm8580_priv *wm8580; - struct snd_soc_codec *codec; + int ret;
wm8580 = kzalloc(sizeof(struct wm8580_priv), GFP_KERNEL); if (wm8580 == NULL) return -ENOMEM;
- codec = &wm8580->codec; - i2c_set_clientdata(i2c, wm8580); - codec->control_data = i2c; - - codec->dev = &i2c->dev; + wm8580->control_data = i2c; + wm8580->control_type = SND_SOC_I2C;
- return wm8580_register(wm8580, SND_SOC_I2C); + ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &soc_codec_dev_wm8580, wm8580_dai, ARRAY_SIZE(wm8580_dai)); + if (ret < 0) + kfree(wm8580); + return ret; }
static int wm8580_i2c_remove(struct i2c_client *client) { - struct wm8580_priv *wm8580 = i2c_get_clientdata(client); - wm8580_unregister(wm8580); + snd_soc_unregister_codec(&client->dev, client->addr); + kfree(i2c_get_clientdata(client)); return 0; }
@@ -972,7 +896,7 @@ static struct i2c_driver wm8580_i2c_driver = {
static int __init wm8580_modinit(void) { - int ret; + int ret = 0;
#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) ret = i2c_add_driver(&wm8580_i2c_driver); @@ -981,7 +905,7 @@ static int __init wm8580_modinit(void) } #endif
- return 0; + return ret; } module_init(wm8580_modinit);
diff --git a/sound/soc/codecs/wm8580.h b/sound/soc/codecs/wm8580.h index 0dfb5dd..676aadb 100644 --- a/sound/soc/codecs/wm8580.h +++ b/sound/soc/codecs/wm8580.h @@ -31,8 +31,8 @@ #define WM8580_DAI_PAIFRX 0 #define WM8580_DAI_PAIFTX 1
-extern struct snd_soc_dai wm8580_dai[]; -extern struct snd_soc_codec_device soc_codec_dev_wm8580; +extern struct snd_soc_dai_driver wm8580_dai[]; +extern struct snd_soc_codec_driver soc_codec_dev_wm8580;
#endif
Moved Wolfson WM87xx CODECs to multi-component model.
This patch changes the probe() and remove() of the CODEC drivers as follows:-
o Make CODEC driver a platform device (non MFD codecs only) o Moved all struct snd_soc_codec list, mutex, etc initialiasation to core. o Removed all static codec pointers (drivers now support > 1 codec dev) o snd_soc_register_pcms() now done by core. o snd_soc_register_dai() folded into snd_soc_register_codec(). o codec cache can now be malloc()ed by core.
Other required changes due to multi-component model :-
o wm8753: dai mode configuration now modifies private data to store mode.
Signed-off-by: Liam Girdwood lrg@slimlogic.co.uk --- sound/soc/codecs/wm8711.c | 199 +++++++---------------- sound/soc/codecs/wm8711.h | 4 +- sound/soc/codecs/wm8727.c | 100 ++---------- sound/soc/codecs/wm8727.h | 4 +- sound/soc/codecs/wm8728.c | 292 +++++++++++----------------------- sound/soc/codecs/wm8728.h | 10 +- sound/soc/codecs/wm8731.c | 213 ++++++++----------------- sound/soc/codecs/wm8731.h | 4 +- sound/soc/codecs/wm8750.c | 269 +++++++++++--------------------- sound/soc/codecs/wm8750.h | 10 +- sound/soc/codecs/wm8753.c | 389 ++++++++++++++++----------------------------- sound/soc/codecs/wm8753.h | 4 +- sound/soc/codecs/wm8776.c | 231 +++++++-------------------- sound/soc/codecs/wm8776.h | 4 +- 14 files changed, 532 insertions(+), 1201 deletions(-)
diff --git a/sound/soc/codecs/wm8711.c b/sound/soc/codecs/wm8711.c index effb14e..d903608 100644 --- a/sound/soc/codecs/wm8711.c +++ b/sound/soc/codecs/wm8711.c @@ -31,11 +31,10 @@
#include "wm8711.h"
-static struct snd_soc_codec *wm8711_codec; - /* codec private data */ struct wm8711_priv { - struct snd_soc_codec codec; + enum snd_soc_control_type bus_type; + void *control_data; u16 reg_cache[WM8711_CACHEREGNUM]; unsigned int sysclk; }; @@ -163,7 +162,7 @@ static int wm8711_hw_params(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { struct snd_soc_codec *codec = dai->codec; - struct wm8711_priv *wm8711 = snd_soc_codec_get_drvdata(codec); + struct wm8711_priv *wm8711 = snd_soc_codec_get_drvdata(codec); u16 iface = snd_soc_read(codec, WM8711_IFACE) & 0xfffc; int i = get_coeff(wm8711->sysclk, params_rate(params)); u16 srate = (coeff_div[i].sr << 2) | @@ -227,7 +226,7 @@ static int wm8711_set_dai_sysclk(struct snd_soc_dai *codec_dai, int clk_id, unsigned int freq, int dir) { struct snd_soc_codec *codec = codec_dai->codec; - struct wm8711_priv *wm8711 = snd_soc_codec_get_drvdata(codec); + struct wm8711_priv *wm8711 = snd_soc_codec_get_drvdata(codec);
switch (freq) { case 11289600: @@ -338,7 +337,7 @@ static struct snd_soc_dai_ops wm8711_ops = { .set_fmt = wm8711_set_dai_fmt, };
-struct snd_soc_dai wm8711_dai = { +struct snd_soc_dai_driver wm8711_dai = { .name = "WM8711", .playback = { .stream_name = "Playback", @@ -351,20 +350,15 @@ struct snd_soc_dai wm8711_dai = { }; EXPORT_SYMBOL_GPL(wm8711_dai);
-static int wm8711_suspend(struct platform_device *pdev, pm_message_t state) +static int wm8711_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; - snd_soc_write(codec, WM8711_ACTIVE, 0x0); wm8711_set_bias_level(codec, SND_SOC_BIAS_OFF); return 0; }
-static int wm8711_resume(struct platform_device *pdev) +static int wm8711_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; @@ -380,163 +374,86 @@ static int wm8711_resume(struct platform_device *pdev) return 0; }
-static int wm8711_probe(struct platform_device *pdev) +static int wm8711_probe(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - int ret = 0; + struct wm8711_priv *wm8711 = snd_soc_codec_get_drvdata(codec); + int ret, reg;
- if (wm8711_codec == NULL) { - dev_err(&pdev->dev, "Codec device not registered\n"); - return -ENODEV; + codec->control_data = wm8711->control_data; + ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8711->bus_type); + if (ret < 0) { + dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); + return ret; }
- socdev->card->codec = wm8711_codec; - codec = wm8711_codec; - - /* register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); + ret = wm8711_reset(codec); if (ret < 0) { - dev_err(codec->dev, "failed to create pcms: %d\n", ret); - goto pcm_err; + dev_err(codec->dev, "Failed to issue reset\n"); + return ret; }
+ wm8711_set_bias_level(codec, SND_SOC_BIAS_STANDBY); + + /* Latch the update bits */ + reg = snd_soc_read(codec, WM8711_LOUT1V); + snd_soc_write(codec, WM8711_LOUT1V, reg | 0x0100); + reg = snd_soc_read(codec, WM8711_ROUT1V); + snd_soc_write(codec, WM8711_ROUT1V, reg | 0x0100); + snd_soc_add_controls(codec, wm8711_snd_controls, ARRAY_SIZE(wm8711_snd_controls)); wm8711_add_widgets(codec);
return ret;
-pcm_err: - return ret; }
/* power down chip */ -static int wm8711_remove(struct platform_device *pdev) +static int wm8711_remove(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - - snd_soc_free_pcms(socdev); - snd_soc_dapm_free(socdev); - + wm8711_set_bias_level(codec, SND_SOC_BIAS_OFF); return 0; }
-struct snd_soc_codec_device soc_codec_dev_wm8711 = { +struct snd_soc_codec_driver soc_codec_dev_wm8711 = { + .name = "WM8711", + .owner = THIS_MODULE, .probe = wm8711_probe, .remove = wm8711_remove, .suspend = wm8711_suspend, .resume = wm8711_resume, + .set_bias_level = wm8711_set_bias_level, + .reg_cache_size = sizeof(wm8711_reg), + .reg_word_size = sizeof(u16), + .reg_cache_default = wm8711_reg, }; EXPORT_SYMBOL_GPL(soc_codec_dev_wm8711);
-static int wm8711_register(struct wm8711_priv *wm8711, - enum snd_soc_control_type control) -{ - int ret; - struct snd_soc_codec *codec = &wm8711->codec; - u16 reg; - - if (wm8711_codec) { - dev_err(codec->dev, "Another WM8711 is registered\n"); - return -EINVAL; - } - - mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - snd_soc_codec_set_drvdata(codec, wm8711); - codec->name = "WM8711"; - codec->owner = THIS_MODULE; - codec->bias_level = SND_SOC_BIAS_OFF; - codec->set_bias_level = wm8711_set_bias_level; - codec->dai = &wm8711_dai; - codec->num_dai = 1; - codec->reg_cache_size = WM8711_CACHEREGNUM; - codec->reg_cache = &wm8711->reg_cache; - - memcpy(codec->reg_cache, wm8711_reg, sizeof(wm8711_reg)); - - ret = snd_soc_codec_set_cache_io(codec, 7, 9, control); - if (ret < 0) { - dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); - goto err; - } - - ret = wm8711_reset(codec); - if (ret < 0) { - dev_err(codec->dev, "Failed to issue reset\n"); - goto err; - } - - wm8711_dai.dev = codec->dev; - - wm8711_set_bias_level(codec, SND_SOC_BIAS_STANDBY); - - /* Latch the update bits */ - reg = snd_soc_read(codec, WM8711_LOUT1V); - snd_soc_write(codec, WM8711_LOUT1V, reg | 0x0100); - reg = snd_soc_read(codec, WM8711_ROUT1V); - snd_soc_write(codec, WM8711_ROUT1V, reg | 0x0100); - - wm8711_codec = codec; - - ret = snd_soc_register_codec(codec); - if (ret != 0) { - dev_err(codec->dev, "Failed to register codec: %d\n", ret); - goto err; - } - - ret = snd_soc_register_dai(&wm8711_dai); - if (ret != 0) { - dev_err(codec->dev, "Failed to register DAI: %d\n", ret); - goto err_codec; - } - - return 0; - -err_codec: - snd_soc_unregister_codec(codec); -err: - kfree(wm8711); - return ret; -} - -static void wm8711_unregister(struct wm8711_priv *wm8711) -{ - wm8711_set_bias_level(&wm8711->codec, SND_SOC_BIAS_OFF); - snd_soc_unregister_dai(&wm8711_dai); - snd_soc_unregister_codec(&wm8711->codec); - kfree(wm8711); - wm8711_codec = NULL; -} - #if defined(CONFIG_SPI_MASTER) static int __devinit wm8711_spi_probe(struct spi_device *spi) { - struct snd_soc_codec *codec; struct wm8711_priv *wm8711; + int ret;
wm8711 = kzalloc(sizeof(struct wm8711_priv), GFP_KERNEL); if (wm8711 == NULL) return -ENOMEM;
- codec = &wm8711->codec; - codec->control_data = spi; - codec->dev = &spi->dev; - - dev_set_drvdata(&spi->dev, wm8711); + spi_set_drvdata(spi, wm8711); + wm8711->control_data = spi; + wm8711->bus_type = SND_SOC_SPI;
- return wm8711_register(wm8711, SND_SOC_SPI); + ret = snd_soc_register_codec(&spi->dev, spi->chip_select, + &soc_codec_dev_wm8711, &wm8711_dai, 1); + if (ret < 0) + kfree(wm8711); + return ret; }
static int __devexit wm8711_spi_remove(struct spi_device *spi) { - struct wm8711_priv *wm8711 = dev_get_drvdata(&spi->dev); - - wm8711_unregister(wm8711); - + snd_soc_unregister_codec(&spi->dev, spi->chip_select); + kfree(spi_get_drvdata(spi)); return 0; }
@@ -552,31 +469,31 @@ static struct spi_driver wm8711_spi_driver = { #endif /* CONFIG_SPI_MASTER */
#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) -static __devinit int wm8711_i2c_probe(struct i2c_client *i2c, +static __devinit int wm8711_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct wm8711_priv *wm8711; - struct snd_soc_codec *codec; + int ret;
wm8711 = kzalloc(sizeof(struct wm8711_priv), GFP_KERNEL); if (wm8711 == NULL) return -ENOMEM;
- codec = &wm8711->codec; - codec->hw_write = (hw_write_t)i2c_master_send; - - i2c_set_clientdata(i2c, wm8711); - codec->control_data = i2c; + i2c_set_clientdata(client, wm8711); + wm8711->control_data = client; + wm8711->bus_type = SND_SOC_I2C;
- codec->dev = &i2c->dev; - - return wm8711_register(wm8711, SND_SOC_I2C); + ret = snd_soc_register_codec(&client->dev, client->addr, + &soc_codec_dev_wm8711, &wm8711_dai, 1); + if (ret < 0) + kfree(wm8711); + return ret; }
static __devexit int wm8711_i2c_remove(struct i2c_client *client) { - struct wm8711_priv *wm8711 = i2c_get_clientdata(client); - wm8711_unregister(wm8711); + snd_soc_unregister_codec(&client->dev, client->addr); + kfree(i2c_get_clientdata(client)); return 0; }
diff --git a/sound/soc/codecs/wm8711.h b/sound/soc/codecs/wm8711.h index 381e84a..a07b465 100644 --- a/sound/soc/codecs/wm8711.h +++ b/sound/soc/codecs/wm8711.h @@ -36,7 +36,7 @@ struct wm8711_setup_data { unsigned short i2c_address; };
-extern struct snd_soc_dai wm8711_dai; -extern struct snd_soc_codec_device soc_codec_dev_wm8711; +extern struct snd_soc_dai_driver wm8711_dai; +extern struct snd_soc_codec_driver soc_codec_dev_wm8711;
#endif diff --git a/sound/soc/codecs/wm8727.c b/sound/soc/codecs/wm8727.c index 1072621..96b9094 100644 --- a/sound/soc/codecs/wm8727.c +++ b/sound/soc/codecs/wm8727.c @@ -33,7 +33,7 @@ SNDRV_PCM_RATE_192000)
-struct snd_soc_dai wm8727_dai = { +struct snd_soc_dai_driver wm8727_dai = { .name = "WM8727", .playback = { .stream_name = "Playback", @@ -45,99 +45,21 @@ struct snd_soc_dai wm8727_dai = { }; EXPORT_SYMBOL_GPL(wm8727_dai);
-static struct snd_soc_codec *wm8727_codec; - -static int wm8727_soc_probe(struct platform_device *pdev) -{ - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - int ret = 0; - - BUG_ON(!wm8727_codec); - - socdev->card->codec = wm8727_codec; - - /* register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret < 0) { - printk(KERN_ERR "wm8727: failed to create pcms\n"); - goto pcm_err; - } - - return ret; - -pcm_err: - kfree(socdev->card->codec); - socdev->card->codec = NULL; - return ret; -} - -static int wm8727_soc_remove(struct platform_device *pdev) -{ - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - - snd_soc_free_pcms(socdev); - - return 0; -} - -struct snd_soc_codec_device soc_codec_dev_wm8727 = { - .probe = wm8727_soc_probe, - .remove = wm8727_soc_remove, +struct snd_soc_codec_driver soc_codec_dev_wm8727 = { + .name = "WM8727", + .owner = THIS_MODULE, }; EXPORT_SYMBOL_GPL(soc_codec_dev_wm8727);
- -static __devinit int wm8727_platform_probe(struct platform_device *pdev) +static __devinit int wm8727_probe(struct platform_device *pdev) { - struct snd_soc_codec *codec; - int ret; - - if (wm8727_codec) { - dev_err(&pdev->dev, "Another WM8727 is registered\n"); - return -EBUSY; - } - - codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); - if (codec == NULL) - return -ENOMEM; - wm8727_codec = codec; - - platform_set_drvdata(pdev, codec); - - mutex_init(&codec->mutex); - codec->dev = &pdev->dev; - codec->name = "WM8727"; - codec->owner = THIS_MODULE; - codec->dai = &wm8727_dai; - codec->num_dai = 1; - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - wm8727_dai.dev = &pdev->dev; - - ret = snd_soc_register_codec(codec); - if (ret != 0) { - dev_err(&pdev->dev, "Failed to register CODEC: %d\n", ret); - goto err; - } - - ret = snd_soc_register_dai(&wm8727_dai); - if (ret != 0) { - dev_err(&pdev->dev, "Failed to register DAI: %d\n", ret); - goto err_codec; - } - -err_codec: - snd_soc_unregister_codec(codec); -err: - kfree(codec); - return ret; + return snd_soc_register_codec(&pdev->dev, pdev->id, + &soc_codec_dev_wm8727, &wm8727_dai, 1); }
-static int __devexit wm8727_platform_remove(struct platform_device *pdev) +static int __devexit wm8727_remove(struct platform_device *pdev) { - snd_soc_unregister_dai(&wm8727_dai); - snd_soc_unregister_codec(platform_get_drvdata(pdev)); + snd_soc_unregister_codec(&pdev->dev, pdev->id); return 0; }
@@ -147,8 +69,8 @@ static struct platform_driver wm8727_codec_driver = { .owner = THIS_MODULE, },
- .probe = wm8727_platform_probe, - .remove = __devexit_p(wm8727_platform_remove), + .probe = wm8727_probe, + .remove = __devexit_p(wm8727_remove), };
static int __init wm8727_init(void) diff --git a/sound/soc/codecs/wm8727.h b/sound/soc/codecs/wm8727.h index ee19aa7..21fa74b 100644 --- a/sound/soc/codecs/wm8727.h +++ b/sound/soc/codecs/wm8727.h @@ -15,7 +15,7 @@ #ifndef WM8727_H_ #define WM8727_H_
-extern struct snd_soc_dai wm8727_dai; -extern struct snd_soc_codec_device soc_codec_dev_wm8727; +extern struct snd_soc_dai_driver wm8727_dai; +extern struct snd_soc_codec_driver soc_codec_dev_wm8727;
#endif /* WM8727_H_ */ diff --git a/sound/soc/codecs/wm8728.c b/sound/soc/codecs/wm8728.c index 34be2d2..5eff03d 100644 --- a/sound/soc/codecs/wm8728.c +++ b/sound/soc/codecs/wm8728.c @@ -29,8 +29,6 @@
#include "wm8728.h"
-struct snd_soc_codec_device soc_codec_dev_wm8728; - /* * We can't read the WM8728 register space so we cache them instead. * Note that the defaults here aren't the physical defaults, we latch @@ -44,6 +42,12 @@ static const u16 wm8728_reg_defaults[] = { 0x100, };
+/* codec private data */ +struct wm8728_priv { + enum snd_soc_control_type control_type; + void *control_data; +}; + static const DECLARE_TLV_DB_SCALE(wm8728_tlv, -12750, 50, 1);
static const struct snd_kcontrol_new wm8728_snd_controls[] = { @@ -96,8 +100,7 @@ static int wm8728_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; u16 dac = snd_soc_read(codec, WM8728_DACCTL);
dac &= ~0x18; @@ -210,7 +213,7 @@ static struct snd_soc_dai_ops wm8728_dai_ops = { .set_fmt = wm8728_set_dai_fmt, };
-struct snd_soc_dai wm8728_dai = { +struct snd_soc_dai_driver wm8728_dai = { .name = "WM8728", .playback = { .stream_name = "Playback", @@ -223,61 +226,31 @@ struct snd_soc_dai wm8728_dai = { }; EXPORT_SYMBOL_GPL(wm8728_dai);
-static int wm8728_suspend(struct platform_device *pdev, pm_message_t state) +static int wm8728_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; - wm8728_set_bias_level(codec, SND_SOC_BIAS_OFF);
return 0; }
-static int wm8728_resume(struct platform_device *pdev) +static int wm8728_resume(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - wm8728_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
return 0; }
-/* - * initialise the WM8728 driver - * register the mixer and dsp interfaces with the kernel - */ -static int wm8728_init(struct snd_soc_device *socdev, - enum snd_soc_control_type control) +static int wm8728_probe(struct snd_soc_codec *codec) { - struct snd_soc_codec *codec = socdev->card->codec; - int ret = 0; - - codec->name = "WM8728"; - codec->owner = THIS_MODULE; - codec->set_bias_level = wm8728_set_bias_level; - codec->dai = &wm8728_dai; - codec->num_dai = 1; - codec->bias_level = SND_SOC_BIAS_OFF; - codec->reg_cache_size = ARRAY_SIZE(wm8728_reg_defaults); - codec->reg_cache = kmemdup(wm8728_reg_defaults, - sizeof(wm8728_reg_defaults), - GFP_KERNEL); - if (codec->reg_cache == NULL) - return -ENOMEM; + struct wm8728_priv *wm8728 = snd_soc_codec_get_drvdata(codec); + int ret;
- ret = snd_soc_codec_set_cache_io(codec, 7, 9, control); + codec->control_data = wm8728->control_data; + ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8728->control_type); if (ret < 0) { printk(KERN_ERR "wm8728: failed to configure cache I/O: %d\n", ret); - goto err; - } - - /* register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret < 0) { - printk(KERN_ERR "wm8728: failed to create pcms\n"); - goto err; + return ret; }
/* power on device */ @@ -288,122 +261,53 @@ static int wm8728_init(struct snd_soc_device *socdev, wm8728_add_widgets(codec);
return ret; - -err: - kfree(codec->reg_cache); - return ret; }
-static struct snd_soc_device *wm8728_socdev; - -#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) - -/* - * WM8728 2 wire address is determined by GPIO5 - * state during powerup. - * low = 0x1a - * high = 0x1b - */ - -static int wm8728_i2c_probe(struct i2c_client *i2c, - const struct i2c_device_id *id) -{ - struct snd_soc_device *socdev = wm8728_socdev; - struct snd_soc_codec *codec = socdev->card->codec; - int ret; - - i2c_set_clientdata(i2c, codec); - codec->control_data = i2c; - - ret = wm8728_init(socdev, SND_SOC_I2C); - if (ret < 0) - pr_err("failed to initialise WM8728\n"); - - return ret; -} - -static int wm8728_i2c_remove(struct i2c_client *client) +static int wm8728_remove(struct snd_soc_codec *codec) { - struct snd_soc_codec *codec = i2c_get_clientdata(client); - kfree(codec->reg_cache); + wm8728_set_bias_level(codec, SND_SOC_BIAS_OFF); return 0; }
-static const struct i2c_device_id wm8728_i2c_id[] = { - { "wm8728", 0 }, - { } -}; -MODULE_DEVICE_TABLE(i2c, wm8728_i2c_id); - -static struct i2c_driver wm8728_i2c_driver = { - .driver = { - .name = "WM8728 I2C Codec", - .owner = THIS_MODULE, - }, - .probe = wm8728_i2c_probe, - .remove = wm8728_i2c_remove, - .id_table = wm8728_i2c_id, +struct snd_soc_codec_driver soc_codec_dev_wm8728 = { + .name = "wm8728", + .probe = wm8728_probe, + .remove = wm8728_remove, + .suspend = wm8728_suspend, + .resume = wm8728_resume, + .owner = THIS_MODULE, + .set_bias_level = wm8728_set_bias_level, + .reg_cache_size = sizeof(wm8728_reg_defaults), + .reg_word_size = sizeof(u16), + .reg_cache_default = wm8728_reg_defaults, }; - -static int wm8728_add_i2c_device(struct platform_device *pdev, - const struct wm8728_setup_data *setup) -{ - struct i2c_board_info info; - struct i2c_adapter *adapter; - struct i2c_client *client; - int ret; - - ret = i2c_add_driver(&wm8728_i2c_driver); - if (ret != 0) { - dev_err(&pdev->dev, "can't add i2c driver\n"); - return ret; - } - - memset(&info, 0, sizeof(struct i2c_board_info)); - info.addr = setup->i2c_address; - strlcpy(info.type, "wm8728", I2C_NAME_SIZE); - - adapter = i2c_get_adapter(setup->i2c_bus); - if (!adapter) { - dev_err(&pdev->dev, "can't get i2c adapter %d\n", - setup->i2c_bus); - goto err_driver; - } - - client = i2c_new_device(adapter, &info); - i2c_put_adapter(adapter); - if (!client) { - dev_err(&pdev->dev, "can't add i2c device at 0x%x\n", - (unsigned int)info.addr); - goto err_driver; - } - - return 0; - -err_driver: - i2c_del_driver(&wm8728_i2c_driver); - return -ENODEV; -} -#endif +EXPORT_SYMBOL_GPL(soc_codec_dev_wm8728);
#if defined(CONFIG_SPI_MASTER) static int __devinit wm8728_spi_probe(struct spi_device *spi) { - struct snd_soc_device *socdev = wm8728_socdev; - struct snd_soc_codec *codec = socdev->card->codec; + struct wm8728_priv *wm8728; int ret;
- codec->control_data = spi; + wm8728 = kzalloc(sizeof(struct wm8728_priv), GFP_KERNEL); + if (wm8728 == NULL) + return -ENOMEM;
- ret = wm8728_init(socdev, SND_SOC_SPI); - if (ret < 0) - dev_err(&spi->dev, "failed to initialise WM8728\n"); + wm8728->control_data = spi; + wm8728->control_type = SND_SOC_SPI; + spi_set_drvdata(spi, wm8728);
+ ret = snd_soc_register_codec(&spi->dev, spi->chip_select, + &soc_codec_dev_wm8728, &wm8728_dai, 1); + if (ret < 0) + kfree(wm8728); return ret; }
static int __devexit wm8728_spi_remove(struct spi_device *spi) { + snd_soc_unregister_codec(&spi->dev, spi->chip_select); + kfree(spi_get_drvdata(spi)); return 0; }
@@ -418,85 +322,81 @@ static struct spi_driver wm8728_spi_driver = { }; #endif /* CONFIG_SPI_MASTER */
-static int wm8728_probe(struct platform_device *pdev) +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) +static __devinit int wm8728_i2c_probe(struct i2c_client *i2c, + const struct i2c_device_id *id) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct wm8728_setup_data *setup; - struct snd_soc_codec *codec; - int ret = 0; + struct wm8728_priv *wm8728; + int ret;
- setup = socdev->codec_data; - codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); - if (codec == NULL) + wm8728 = kzalloc(sizeof(struct wm8728_priv), GFP_KERNEL); + if (wm8728 == NULL) return -ENOMEM;
- socdev->card->codec = codec; - mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); + i2c_set_clientdata(i2c, wm8728); + wm8728->control_data = i2c; + wm8728->control_type = SND_SOC_I2C; + + ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &soc_codec_dev_wm8728, &wm8728_dai, 1); + if (ret < 0) + kfree(wm8728); + return ret; +} + +static __devexit int wm8728_i2c_remove(struct i2c_client *client) +{ + snd_soc_unregister_codec(&client->dev, client->addr); + kfree(i2c_get_clientdata(client)); + return 0; +} + +static const struct i2c_device_id wm8728_i2c_id[] = { + { "wm8728", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, wm8728_i2c_id);
- wm8728_socdev = socdev; - ret = -ENODEV; +static struct i2c_driver wm8728_i2c_driver = { + .driver = { + .name = "wm8728 I2C Codec", + .owner = THIS_MODULE, + }, + .probe = wm8728_i2c_probe, + .remove = __devexit_p(wm8728_i2c_remove), + .id_table = wm8728_i2c_id, +}; +#endif
+static int __init wm8728_modinit(void) +{ + int ret = 0; #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) - if (setup->i2c_address) { - ret = wm8728_add_i2c_device(pdev, setup); + ret = i2c_add_driver(&wm8728_i2c_driver); + if (ret != 0) { + printk(KERN_ERR "Failed to register wm8728 I2C driver: %d\n", + ret); } #endif #if defined(CONFIG_SPI_MASTER) - if (setup->spi) { - ret = spi_register_driver(&wm8728_spi_driver); - if (ret != 0) - printk(KERN_ERR "can't add spi driver"); + ret = spi_register_driver(&wm8728_spi_driver); + if (ret != 0) { + printk(KERN_ERR "Failed to register wm8728 SPI driver: %d\n", + ret); } #endif - - if (ret != 0) - kfree(codec); - return ret; } +module_init(wm8728_modinit);
-/* power down chip */ -static int wm8728_remove(struct platform_device *pdev) +static void __exit wm8728_exit(void) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - - if (codec->control_data) - wm8728_set_bias_level(codec, SND_SOC_BIAS_OFF); - - snd_soc_free_pcms(socdev); - snd_soc_dapm_free(socdev); #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) - i2c_unregister_device(codec->control_data); i2c_del_driver(&wm8728_i2c_driver); #endif #if defined(CONFIG_SPI_MASTER) spi_unregister_driver(&wm8728_spi_driver); #endif - kfree(codec); - - return 0; -} - -struct snd_soc_codec_device soc_codec_dev_wm8728 = { - .probe = wm8728_probe, - .remove = wm8728_remove, - .suspend = wm8728_suspend, - .resume = wm8728_resume, -}; -EXPORT_SYMBOL_GPL(soc_codec_dev_wm8728); - -static int __init wm8728_modinit(void) -{ - return snd_soc_register_dai(&wm8728_dai); -} -module_init(wm8728_modinit); - -static void __exit wm8728_exit(void) -{ - snd_soc_unregister_dai(&wm8728_dai); } module_exit(wm8728_exit);
diff --git a/sound/soc/codecs/wm8728.h b/sound/soc/codecs/wm8728.h index d269c13..3769a7f 100644 --- a/sound/soc/codecs/wm8728.h +++ b/sound/soc/codecs/wm8728.h @@ -18,13 +18,7 @@ #define WM8728_DACCTL 0x02 #define WM8728_IFCTL 0x03
-struct wm8728_setup_data { - int spi; - int i2c_bus; - unsigned short i2c_address; -}; - -extern struct snd_soc_dai wm8728_dai; -extern struct snd_soc_codec_device soc_codec_dev_wm8728; +extern struct snd_soc_dai_driver wm8728_dai; +extern struct snd_soc_codec_driver soc_codec_dev_wm8728;
#endif diff --git a/sound/soc/codecs/wm8731.c b/sound/soc/codecs/wm8731.c index 0ab9b63..3abe6ee 100644 --- a/sound/soc/codecs/wm8731.c +++ b/sound/soc/codecs/wm8731.c @@ -32,9 +32,6 @@
#include "wm8731.h"
-static struct snd_soc_codec *wm8731_codec; -struct snd_soc_codec_device soc_codec_dev_wm8731; - #define WM8731_NUM_SUPPLIES 4 static const char *wm8731_supply_names[WM8731_NUM_SUPPLIES] = { "AVDD", @@ -45,7 +42,8 @@ static const char *wm8731_supply_names[WM8731_NUM_SUPPLIES] = {
/* codec private data */ struct wm8731_priv { - struct snd_soc_codec codec; + enum snd_soc_control_type control_type; + void *control_data; struct regulator_bulk_data supplies[WM8731_NUM_SUPPLIES]; u16 reg_cache[WM8731_CACHEREGNUM]; unsigned int sysclk; @@ -222,9 +220,7 @@ static int wm8731_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, 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 = dai->codec; struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec); u16 iface = snd_soc_read(codec, WM8731_IFACE) & 0xfff3; int i = get_coeff(wm8731->sysclk, params_rate(params)); @@ -252,9 +248,7 @@ static int wm8731_hw_params(struct snd_pcm_substream *substream, static int wm8731_pcm_prepare(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 = dai->codec;
/* set active */ snd_soc_write(codec, WM8731_ACTIVE, 0x0001); @@ -265,9 +259,7 @@ static int wm8731_pcm_prepare(struct snd_pcm_substream *substream, static void wm8731_shutdown(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 = dai->codec;
/* deactivate */ if (!codec->active) { @@ -428,7 +420,7 @@ static struct snd_soc_dai_ops wm8731_dai_ops = { .set_fmt = wm8731_set_dai_fmt, };
-struct snd_soc_dai wm8731_dai = { +struct snd_soc_dai_driver wm8731_dai = { .name = "WM8731", .playback = { .stream_name = "Playback", @@ -448,21 +440,15 @@ struct snd_soc_dai wm8731_dai = { EXPORT_SYMBOL_GPL(wm8731_dai);
#ifdef CONFIG_PM -static int wm8731_suspend(struct platform_device *pdev, pm_message_t state) +static int wm8731_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; - wm8731_set_bias_level(codec, SND_SOC_BIAS_OFF);
return 0; }
-static int wm8731_resume(struct platform_device *pdev) +static int wm8731_resume(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - wm8731_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
return 0; @@ -472,88 +458,18 @@ static int wm8731_resume(struct platform_device *pdev) #define wm8731_resume NULL #endif
-static int wm8731_probe(struct platform_device *pdev) +static int wm8731_probe(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - int ret = 0; - - if (wm8731_codec == NULL) { - dev_err(&pdev->dev, "Codec device not registered\n"); - return -ENODEV; - } - - socdev->card->codec = wm8731_codec; - codec = wm8731_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, wm8731_snd_controls, - ARRAY_SIZE(wm8731_snd_controls)); - wm8731_add_widgets(codec); - - return ret; - -pcm_err: - return ret; -} - -/* power down chip */ -static int wm8731_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_wm8731 = { - .probe = wm8731_probe, - .remove = wm8731_remove, - .suspend = wm8731_suspend, - .resume = wm8731_resume, -}; -EXPORT_SYMBOL_GPL(soc_codec_dev_wm8731); - -static int wm8731_register(struct wm8731_priv *wm8731, - enum snd_soc_control_type control) -{ - int ret, i; - struct snd_soc_codec *codec = &wm8731->codec; - - if (wm8731_codec) { - dev_err(codec->dev, "Another WM8731 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, wm8731); - codec->name = "WM8731"; - codec->owner = THIS_MODULE; - codec->bias_level = SND_SOC_BIAS_OFF; - codec->set_bias_level = wm8731_set_bias_level; - codec->dai = &wm8731_dai; - codec->num_dai = 1; - codec->reg_cache_size = WM8731_CACHEREGNUM; - codec->reg_cache = &wm8731->reg_cache; + struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec); + int ret = 0, i;
- memcpy(codec->reg_cache, wm8731_reg, sizeof(wm8731_reg)); + codec->bias_level = SND_SOC_BIAS_OFF, + codec->control_data = wm8731->control_data;
- ret = snd_soc_codec_set_cache_io(codec, 7, 9, control); + ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8731->control_type); if (ret < 0) { dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); - goto err; + return ret; }
for (i = 0; i < ARRAY_SIZE(wm8731->supplies); i++) @@ -563,7 +479,7 @@ static int wm8731_register(struct wm8731_priv *wm8731, wm8731->supplies); if (ret != 0) { dev_err(codec->dev, "Failed to request supplies: %d\n", ret); - goto err; + return ret; }
ret = regulator_bulk_enable(ARRAY_SIZE(wm8731->supplies), @@ -579,8 +495,6 @@ static int wm8731_register(struct wm8731_priv *wm8731, goto err_regulator_enable; }
- wm8731_dai.dev = codec->dev; - wm8731_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
/* Latch the update bits */ @@ -592,72 +506,76 @@ static int wm8731_register(struct wm8731_priv *wm8731, /* Disable bypass path by default */ snd_soc_update_bits(codec, WM8731_APANA, 0x4, 0);
- wm8731_codec = codec; - - ret = snd_soc_register_codec(codec); - if (ret != 0) { - dev_err(codec->dev, "Failed to register codec: %d\n", ret); - goto err_regulator_enable; - } - - ret = snd_soc_register_dai(&wm8731_dai); - if (ret != 0) { - dev_err(codec->dev, "Failed to register DAI: %d\n", ret); - snd_soc_unregister_codec(codec); - goto err_codec; - } + snd_soc_add_controls(codec, wm8731_snd_controls, + ARRAY_SIZE(wm8731_snd_controls)); + wm8731_add_widgets(codec);
/* Regulators will have been enabled by bias management */ regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies);
return 0;
-err_codec: - snd_soc_unregister_codec(codec); err_regulator_enable: regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies); err_regulator_get: regulator_bulk_free(ARRAY_SIZE(wm8731->supplies), wm8731->supplies); -err: + kfree(wm8731); return ret; }
-static void wm8731_unregister(struct wm8731_priv *wm8731) +/* power down chip */ +static int wm8731_remove(struct snd_soc_codec *codec) { - wm8731_set_bias_level(&wm8731->codec, SND_SOC_BIAS_OFF); - snd_soc_unregister_dai(&wm8731_dai); - snd_soc_unregister_codec(&wm8731->codec); + struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec); + + wm8731_set_bias_level(codec, SND_SOC_BIAS_OFF); + + regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies); regulator_bulk_free(ARRAY_SIZE(wm8731->supplies), wm8731->supplies); - kfree(wm8731); - wm8731_codec = NULL; + + return 0; }
+struct snd_soc_codec_driver soc_codec_dev_wm8731 = { + .name = "WM8731", + .probe = wm8731_probe, + .remove = wm8731_remove, + .suspend = wm8731_suspend, + .resume = wm8731_resume, + .owner = THIS_MODULE, + .set_bias_level = wm8731_set_bias_level, + .reg_cache_size = sizeof(wm8731_reg), + .reg_word_size = sizeof(u16), + .reg_cache_default = wm8731_reg, +}; +EXPORT_SYMBOL_GPL(soc_codec_dev_wm8731); + #if defined(CONFIG_SPI_MASTER) static int __devinit wm8731_spi_probe(struct spi_device *spi) { - struct snd_soc_codec *codec; struct wm8731_priv *wm8731; + int ret;
wm8731 = kzalloc(sizeof(struct wm8731_priv), GFP_KERNEL); if (wm8731 == NULL) return -ENOMEM;
- codec = &wm8731->codec; - codec->control_data = spi; - codec->dev = &spi->dev; + wm8731->control_data = spi; + wm8731->control_type = SND_SOC_SPI; + spi_set_drvdata(spi, wm8731);
- dev_set_drvdata(&spi->dev, wm8731); - - return wm8731_register(wm8731, SND_SOC_SPI); + ret = snd_soc_register_codec(&spi->dev, spi->chip_select, + &soc_codec_dev_wm8731, &wm8731_dai, 1); + if (ret < 0) + kfree(wm8731); + return ret; }
static int __devexit wm8731_spi_remove(struct spi_device *spi) { - struct wm8731_priv *wm8731 = dev_get_drvdata(&spi->dev); - - wm8731_unregister(wm8731); - + snd_soc_unregister_codec(&spi->dev, spi->chip_select); + kfree(spi_get_drvdata(spi)); return 0; }
@@ -677,26 +595,27 @@ static __devinit int wm8731_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct wm8731_priv *wm8731; - struct snd_soc_codec *codec; + int ret;
wm8731 = kzalloc(sizeof(struct wm8731_priv), GFP_KERNEL); if (wm8731 == NULL) return -ENOMEM;
- codec = &wm8731->codec; - i2c_set_clientdata(i2c, wm8731); - codec->control_data = i2c; - - codec->dev = &i2c->dev; + wm8731->control_data = i2c; + wm8731->control_type = SND_SOC_I2C;
- return wm8731_register(wm8731, SND_SOC_I2C); + ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &soc_codec_dev_wm8731, &wm8731_dai, 1); + if (ret < 0) + kfree(wm8731); + return ret; }
static __devexit int wm8731_i2c_remove(struct i2c_client *client) { - struct wm8731_priv *wm8731 = i2c_get_clientdata(client); - wm8731_unregister(wm8731); + snd_soc_unregister_codec(&client->dev, client->addr); + kfree(i2c_get_clientdata(client)); return 0; }
@@ -719,7 +638,7 @@ static struct i2c_driver wm8731_i2c_driver = {
static int __init wm8731_modinit(void) { - int ret; + int ret = 0; #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) ret = i2c_add_driver(&wm8731_i2c_driver); if (ret != 0) { @@ -734,7 +653,7 @@ static int __init wm8731_modinit(void) ret); } #endif - return 0; + return ret; } module_init(wm8731_modinit);
diff --git a/sound/soc/codecs/wm8731.h b/sound/soc/codecs/wm8731.h index cd7b806..757c8a5 100644 --- a/sound/soc/codecs/wm8731.h +++ b/sound/soc/codecs/wm8731.h @@ -34,7 +34,7 @@ #define WM8731_SYSCLK 0 #define WM8731_DAI 0
-extern struct snd_soc_dai wm8731_dai; -extern struct snd_soc_codec_device soc_codec_dev_wm8731; +extern struct snd_soc_dai_driver wm8731_dai; +extern struct snd_soc_codec_driver soc_codec_dev_wm8731;
#endif diff --git a/sound/soc/codecs/wm8750.c b/sound/soc/codecs/wm8750.c index 9407e19..eb10567 100644 --- a/sound/soc/codecs/wm8750.c +++ b/sound/soc/codecs/wm8750.c @@ -52,7 +52,8 @@ static const u16 wm8750_reg[] = { /* codec private data */ struct wm8750_priv { unsigned int sysclk; - struct snd_soc_codec codec; + enum snd_soc_control_type control_type; + void *control_data; u16 reg_cache[ARRAY_SIZE(wm8750_reg)]; };
@@ -560,8 +561,7 @@ static int wm8750_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 wm8750_priv *wm8750 = snd_soc_codec_get_drvdata(codec); u16 iface = snd_soc_read(codec, WM8750_IFACE) & 0x1f3; u16 srate = snd_soc_read(codec, WM8750_SRATE) & 0x1c0; @@ -649,7 +649,7 @@ static struct snd_soc_dai_ops wm8750_dai_ops = { .set_sysclk = wm8750_set_dai_sysclk, };
-struct snd_soc_dai wm8750_dai = { +struct snd_soc_dai_driver wm8750_dai = { .name = "WM8750", .playback = { .stream_name = "Playback", @@ -667,19 +667,14 @@ struct snd_soc_dai wm8750_dai = { }; EXPORT_SYMBOL_GPL(wm8750_dai);
-static int wm8750_suspend(struct platform_device *pdev, pm_message_t state) +static int wm8750_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; - wm8750_set_bias_level(codec, SND_SOC_BIAS_OFF); return 0; }
-static int wm8750_resume(struct platform_device *pdev) +static int wm8750_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; @@ -698,100 +693,22 @@ static int wm8750_resume(struct platform_device *pdev) return 0; }
-static struct snd_soc_codec *wm8750_codec; - -static int wm8750_probe(struct platform_device *pdev) +static int wm8750_probe(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - int ret = 0; - - if (!wm8750_codec) { - dev_err(&pdev->dev, "WM8750 codec not yet registered\n"); - return -EINVAL; - } - - socdev->card->codec = wm8750_codec; - codec = wm8750_codec; - - /* register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret < 0) { - printk(KERN_ERR "wm8750: failed to create pcms\n"); - goto err; - } - - snd_soc_add_controls(codec, wm8750_snd_controls, - ARRAY_SIZE(wm8750_snd_controls)); - wm8750_add_widgets(codec); - - return 0; - -err: - return ret; -} - -/* power down chip */ -static int wm8750_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_wm8750 = { - .probe = wm8750_probe, - .remove = wm8750_remove, - .suspend = wm8750_suspend, - .resume = wm8750_resume, -}; -EXPORT_SYMBOL_GPL(soc_codec_dev_wm8750); - -/* - * initialise the WM8750 driver - * register the mixer and dsp interfaces with the kernel - */ -static int wm8750_register(struct wm8750_priv *wm8750, - enum snd_soc_control_type control) -{ - struct snd_soc_codec *codec = &wm8750->codec; - int reg, ret = 0; - - if (wm8750_codec) { - dev_err(codec->dev, "Multiple WM8750 devices not supported\n"); - ret = -EINVAL; - goto err; - } - - mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - codec->name = "WM8750"; - codec->owner = THIS_MODULE; - codec->bias_level = SND_SOC_BIAS_STANDBY; - codec->set_bias_level = wm8750_set_bias_level; - codec->dai = &wm8750_dai; - codec->num_dai = 1; - codec->reg_cache_size = ARRAY_SIZE(wm8750->reg_cache) + 1; - codec->reg_cache = &wm8750->reg_cache; - snd_soc_codec_set_drvdata(codec, wm8750); - - memcpy(codec->reg_cache, wm8750_reg, sizeof(wm8750->reg_cache)); + struct wm8750_priv *wm8750 = snd_soc_codec_get_drvdata(codec); + int reg, ret;
- ret = snd_soc_codec_set_cache_io(codec, 7, 9, control); + codec->control_data = wm8750->control_data; + ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8750->control_type); if (ret < 0) { printk(KERN_ERR "wm8750: failed to set cache I/O: %d\n", ret); - goto err; + return ret; }
ret = wm8750_reset(codec); if (ret < 0) { printk(KERN_ERR "wm8750: failed to reset: %d\n", ret); - goto err; + return ret; }
/* charge output caps */ @@ -815,141 +732,135 @@ static int wm8750_register(struct wm8750_priv *wm8750, reg = snd_soc_read(codec, WM8750_RINVOL); snd_soc_write(codec, WM8750_RINVOL, reg | 0x0100);
- wm8750_codec = codec; - - ret = snd_soc_register_codec(codec); - if (ret != 0) { - dev_err(codec->dev, "Failed to register codec: %d\n", ret); - goto err; - } - - ret = snd_soc_register_dais(&wm8750_dai, 1); - if (ret != 0) { - dev_err(codec->dev, "Failed to register DAIs: %d\n", ret); - goto err_codec; - } - - return 0; - -err_codec: - snd_soc_unregister_codec(codec); -err: - kfree(wm8750); + snd_soc_add_controls(codec, wm8750_snd_controls, + ARRAY_SIZE(wm8750_snd_controls)); + wm8750_add_widgets(codec); return ret; }
-static void wm8750_unregister(struct wm8750_priv *wm8750) +static int wm8750_remove(struct snd_soc_codec *codec) { - wm8750_set_bias_level(&wm8750->codec, SND_SOC_BIAS_OFF); - snd_soc_unregister_dais(&wm8750_dai, 1); - snd_soc_unregister_codec(&wm8750->codec); - kfree(wm8750); - wm8750_codec = NULL; + wm8750_set_bias_level(codec, SND_SOC_BIAS_OFF); + return 0; }
-#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) - -/* - * WM8750 2 wire address is determined by GPIO5 - * state during powerup. - * low = 0x1a - * high = 0x1b - */ +struct snd_soc_codec_driver soc_codec_dev_wm8750 = { + .name = "wm8750", + .probe = wm8750_probe, + .remove = wm8750_remove, + .suspend = wm8750_suspend, + .resume = wm8750_resume, + .owner = THIS_MODULE, + .set_bias_level = wm8750_set_bias_level, + .reg_cache_size = sizeof(wm8750_reg), + .reg_word_size = sizeof(u16), + .reg_cache_default = wm8750_reg, +}; +EXPORT_SYMBOL_GPL(soc_codec_dev_wm8750);
-static int wm8750_i2c_probe(struct i2c_client *i2c, - const struct i2c_device_id *id) +#if defined(CONFIG_SPI_MASTER) +static int __devinit wm8750_spi_probe(struct spi_device *spi) { - struct snd_soc_codec *codec; struct wm8750_priv *wm8750; + int ret;
wm8750 = kzalloc(sizeof(struct wm8750_priv), GFP_KERNEL); if (wm8750 == NULL) return -ENOMEM;
- codec = &wm8750->codec; - codec->control_data = i2c; - i2c_set_clientdata(i2c, wm8750); - - codec->dev = &i2c->dev; + wm8750->control_data = spi; + wm8750->control_type = SND_SOC_SPI; + spi_set_drvdata(spi, wm8750);
- return wm8750_register(wm8750, SND_SOC_I2C); + ret = snd_soc_register_codec(&spi->dev, spi->chip_select, + &soc_codec_dev_wm8750, &wm8750_dai, 1); + if (ret < 0) + kfree(wm8750); + return ret; }
-static int wm8750_i2c_remove(struct i2c_client *client) +static int __devexit wm8750_spi_remove(struct spi_device *spi) { - struct wm8750_priv *wm8750 = i2c_get_clientdata(client); - wm8750_unregister(wm8750); + snd_soc_unregister_codec(&spi->dev, spi->chip_select); + kfree(spi_get_drvdata(spi)); return 0; }
-static const struct i2c_device_id wm8750_i2c_id[] = { - { "wm8750", 0 }, - { } -}; -MODULE_DEVICE_TABLE(i2c, wm8750_i2c_id); - -static struct i2c_driver wm8750_i2c_driver = { +static struct spi_driver wm8750_spi_driver = { .driver = { - .name = "WM8750 I2C Codec", - .owner = THIS_MODULE, + .name = "wm8750", + .bus = &spi_bus_type, + .owner = THIS_MODULE, }, - .probe = wm8750_i2c_probe, - .remove = wm8750_i2c_remove, - .id_table = wm8750_i2c_id, + .probe = wm8750_spi_probe, + .remove = __devexit_p(wm8750_spi_remove), }; -#endif +#endif /* CONFIG_SPI_MASTER */
-#if defined(CONFIG_SPI_MASTER) -static int __devinit wm8750_spi_probe(struct spi_device *spi) +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) +static __devinit int wm8750_i2c_probe(struct i2c_client *i2c, + const struct i2c_device_id *id) { - struct snd_soc_codec *codec; struct wm8750_priv *wm8750; + int ret;
wm8750 = kzalloc(sizeof(struct wm8750_priv), GFP_KERNEL); if (wm8750 == NULL) return -ENOMEM;
- codec = &wm8750->codec; - codec->control_data = spi; - codec->dev = &spi->dev; - - dev_set_drvdata(&spi->dev, wm8750); + i2c_set_clientdata(i2c, wm8750); + wm8750->control_data = i2c; + wm8750->control_type = SND_SOC_I2C;
- return wm8750_register(wm8750, SND_SOC_SPI); + ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &soc_codec_dev_wm8750, &wm8750_dai, 1); + if (ret < 0) + kfree(wm8750); + return ret; }
-static int __devexit wm8750_spi_remove(struct spi_device *spi) +static __devexit int wm8750_i2c_remove(struct i2c_client *client) { - struct wm8750_priv *wm8750 = dev_get_drvdata(&spi->dev); - wm8750_unregister(wm8750); + snd_soc_unregister_codec(&client->dev, client->addr); + kfree(i2c_get_clientdata(client)); return 0; }
-static struct spi_driver wm8750_spi_driver = { +static const struct i2c_device_id wm8750_i2c_id[] = { + { "wm8750", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, wm8750_i2c_id); + +static struct i2c_driver wm8750_i2c_driver = { .driver = { - .name = "wm8750", - .bus = &spi_bus_type, - .owner = THIS_MODULE, + .name = "wm8750 I2C Codec", + .owner = THIS_MODULE, }, - .probe = wm8750_spi_probe, - .remove = __devexit_p(wm8750_spi_remove), + .probe = wm8750_i2c_probe, + .remove = __devexit_p(wm8750_i2c_remove), + .id_table = wm8750_i2c_id, }; #endif
static int __init wm8750_modinit(void) { - int ret; + int ret = 0; #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) ret = i2c_add_driver(&wm8750_i2c_driver); - if (ret != 0) - pr_err("Failed to register WM8750 I2C driver: %d\n", ret); + if (ret != 0) { + printk(KERN_ERR "Failed to register wm8750 I2C driver: %d\n", + ret); + } #endif #if defined(CONFIG_SPI_MASTER) ret = spi_register_driver(&wm8750_spi_driver); - if (ret != 0) - pr_err("Failed to register WM8750 SPI driver: %d\n", ret); + if (ret != 0) { + printk(KERN_ERR "Failed to register wm8750 SPI driver: %d\n", + ret); + } #endif - return 0; + return ret; } module_init(wm8750_modinit);
diff --git a/sound/soc/codecs/wm8750.h b/sound/soc/codecs/wm8750.h index 1dc100e..e90891b 100644 --- a/sound/soc/codecs/wm8750.h +++ b/sound/soc/codecs/wm8750.h @@ -57,13 +57,7 @@
#define WM8750_SYSCLK 0
-struct wm8750_setup_data { - int spi; - int i2c_bus; - unsigned short i2c_address; -}; - -extern struct snd_soc_dai wm8750_dai; -extern struct snd_soc_codec_device soc_codec_dev_wm8750; +extern struct snd_soc_dai_driver wm8750_dai; +extern struct snd_soc_codec_driver soc_codec_dev_wm8750;
#endif diff --git a/sound/soc/codecs/wm8753.c b/sound/soc/codecs/wm8753.c index b59f349..bd0676f 100644 --- a/sound/soc/codecs/wm8753.c +++ b/sound/soc/codecs/wm8753.c @@ -57,7 +57,7 @@ module_param(caps_charge, int, 0); MODULE_PARM_DESC(caps_charge, "WM8753 cap charge time (msecs)");
static void wm8753_set_dai_mode(struct snd_soc_codec *codec, - unsigned int mode); + struct snd_soc_dai *dai, unsigned int hifi);
/* * wm8753 register cache @@ -85,10 +85,12 @@ static const u16 wm8753_reg[] = {
/* codec private data */ struct wm8753_priv { + enum snd_soc_control_type control_type; + void *control_data; unsigned int sysclk; unsigned int pcmclk; - struct snd_soc_codec codec; u16 reg_cache[ARRAY_SIZE(wm8753_reg)]; + int dai_func; };
/* @@ -228,6 +230,7 @@ static int wm8753_set_dai(struct snd_kcontrol *kcontrol, { struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); int mode = wm8753_read_reg_cache(codec, WM8753_IOCTL); + struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec);
if (((mode & 0xc) >> 2) == ucontrol->value.integer.value[0]) return 0; @@ -235,8 +238,7 @@ static int wm8753_set_dai(struct snd_kcontrol *kcontrol, mode &= 0xfff3; mode |= (ucontrol->value.integer.value[0] << 2);
- wm8753_write(codec, WM8753_IOCTL, mode); - wm8753_set_dai_mode(codec, ucontrol->value.integer.value[0]); + wm8753->dai_func = ucontrol->value.integer.value[0]; return 1; }
@@ -904,6 +906,13 @@ static int wm8753_vdac_adc_set_dai_fmt(struct snd_soc_dai *codec_dai, return 0; }
+static int wm8753_pcm_startup(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + wm8753_set_dai_mode(dai->codec, dai, 0); + return 0; +} + /* * Set PCM DAI bit size and sample rate. */ @@ -912,8 +921,7 @@ static int wm8753_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 wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec); u16 voice = wm8753_read_reg_cache(codec, WM8753_PCM) & 0x01f3; u16 srate = wm8753_read_reg_cache(codec, WM8753_SRATE1) & 0x017f; @@ -1138,6 +1146,13 @@ static int wm8753_i2s_set_dai_fmt(struct snd_soc_dai *codec_dai, return 0; }
+static int wm8753_i2s_startup(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + wm8753_set_dai_mode(dai->codec, dai, 1); + return 0; +} + /* * Set PCM DAI bit size and sample rate. */ @@ -1146,8 +1161,7 @@ static int wm8753_i2s_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 wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec); u16 srate = wm8753_read_reg_cache(codec, WM8753_SRATE1) & 0x01c0; u16 hifi = wm8753_read_reg_cache(codec, WM8753_HIFI) & 0x01f3; @@ -1240,12 +1254,12 @@ static int wm8753_mute(struct snd_soc_dai *dai, int mute) { struct snd_soc_codec *codec = dai->codec; u16 mute_reg = wm8753_read_reg_cache(codec, WM8753_DAC) & 0xfff7; + struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec);
/* the digital mute covers the HiFi and Voice DAC's on the WM8753. * make sure we check if they are not both active when we mute */ - if (mute && dai->id == 1) { - if (!wm8753_dai[WM8753_DAI_VOICE].playback.active || - !wm8753_dai[WM8753_DAI_HIFI].playback.active) + if (mute && wm8753->dai_func == 1) { + if (!codec->active) wm8753_write(codec, WM8753_DAC, mute_reg | 0x8); } else { if (mute) @@ -1303,6 +1317,7 @@ static int wm8753_set_bias_level(struct snd_soc_codec *codec, * 4. Voice disabled - HIFI over HIFI, uses voice DAI LRC for capture */ static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode1 = { + .startup = wm8753_i2s_startup, .hw_params = wm8753_i2s_hw_params, .digital_mute = wm8753_mute, .set_fmt = wm8753_mode1h_set_dai_fmt, @@ -1312,6 +1327,7 @@ static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode1 = { };
static struct snd_soc_dai_ops wm8753_dai_ops_voice_mode1 = { + .startup = wm8753_pcm_startup, .hw_params = wm8753_pcm_hw_params, .digital_mute = wm8753_mute, .set_fmt = wm8753_mode1v_set_dai_fmt, @@ -1321,6 +1337,7 @@ static struct snd_soc_dai_ops wm8753_dai_ops_voice_mode1 = { };
static struct snd_soc_dai_ops wm8753_dai_ops_voice_mode2 = { + .startup = wm8753_pcm_startup, .hw_params = wm8753_pcm_hw_params, .digital_mute = wm8753_mute, .set_fmt = wm8753_mode2_set_dai_fmt, @@ -1330,6 +1347,7 @@ static struct snd_soc_dai_ops wm8753_dai_ops_voice_mode2 = { };
static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode3 = { + .startup = wm8753_i2s_startup, .hw_params = wm8753_i2s_hw_params, .digital_mute = wm8753_mute, .set_fmt = wm8753_mode3_4_set_dai_fmt, @@ -1339,6 +1357,7 @@ static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode3 = { };
static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode4 = { + .startup = wm8753_i2s_startup, .hw_params = wm8753_i2s_hw_params, .digital_mute = wm8753_mute, .set_fmt = wm8753_mode3_4_set_dai_fmt, @@ -1347,10 +1366,9 @@ static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode4 = { .set_sysclk = wm8753_set_dai_sysclk, };
-static const struct snd_soc_dai wm8753_all_dai[] = { +static struct snd_soc_dai_driver wm8753_all_dai[] = { /* DAI HiFi mode 1 */ { .name = "WM8753 HiFi", - .id = 1, .playback = { .stream_name = "HiFi Playback", .channels_min = 1, @@ -1367,7 +1385,6 @@ static const struct snd_soc_dai wm8753_all_dai[] = { }, /* DAI Voice mode 1 */ { .name = "WM8753 Voice", - .id = 1, .playback = { .stream_name = "Voice Playback", .channels_min = 1, @@ -1384,11 +1401,9 @@ static const struct snd_soc_dai wm8753_all_dai[] = { }, /* DAI HiFi mode 2 - dummy */ { .name = "WM8753 HiFi", - .id = 2, }, /* DAI Voice mode 2 */ { .name = "WM8753 Voice", - .id = 2, .playback = { .stream_name = "Voice Playback", .channels_min = 1, @@ -1405,7 +1420,6 @@ static const struct snd_soc_dai wm8753_all_dai[] = { }, /* DAI HiFi mode 3 */ { .name = "WM8753 HiFi", - .id = 3, .playback = { .stream_name = "HiFi Playback", .channels_min = 1, @@ -1422,11 +1436,9 @@ static const struct snd_soc_dai wm8753_all_dai[] = { }, /* DAI Voice mode 3 - dummy */ { .name = "WM8753 Voice", - .id = 3, }, /* DAI HiFi mode 4 */ { .name = "WM8753 HiFi", - .id = 4, .playback = { .stream_name = "HiFi Playback", .channels_min = 1, @@ -1443,11 +1455,10 @@ static const struct snd_soc_dai wm8753_all_dai[] = { }, /* DAI Voice mode 4 - dummy */ { .name = "WM8753 Voice", - .id = 4, }, };
-struct snd_soc_dai wm8753_dai[] = { +struct snd_soc_dai_driver wm8753_dai[] = { { .name = "WM8753 DAI 0", }, @@ -1457,43 +1468,18 @@ struct snd_soc_dai wm8753_dai[] = { }; EXPORT_SYMBOL_GPL(wm8753_dai);
-static void wm8753_set_dai_mode(struct snd_soc_codec *codec, unsigned int mode) +static void wm8753_set_dai_mode(struct snd_soc_codec *codec, + struct snd_soc_dai *dai, unsigned int hifi) { - if (mode < 4) { - int playback_active, capture_active, codec_active, pop_wait; - void *private_data; - struct list_head list; - - playback_active = wm8753_dai[0].playback.active; - capture_active = wm8753_dai[0].capture.active; - codec_active = wm8753_dai[0].active; - private_data = wm8753_dai[0].private_data; - pop_wait = wm8753_dai[0].pop_wait; - list = wm8753_dai[0].list; - wm8753_dai[0] = wm8753_all_dai[mode << 1]; - wm8753_dai[0].playback.active = playback_active; - wm8753_dai[0].capture.active = capture_active; - wm8753_dai[0].active = codec_active; - wm8753_dai[0].private_data = private_data; - wm8753_dai[0].pop_wait = pop_wait; - wm8753_dai[0].list = list; - - playback_active = wm8753_dai[1].playback.active; - capture_active = wm8753_dai[1].capture.active; - codec_active = wm8753_dai[1].active; - private_data = wm8753_dai[1].private_data; - pop_wait = wm8753_dai[1].pop_wait; - list = wm8753_dai[1].list; - wm8753_dai[1] = wm8753_all_dai[(mode << 1) + 1]; - wm8753_dai[1].playback.active = playback_active; - wm8753_dai[1].capture.active = capture_active; - wm8753_dai[1].active = codec_active; - wm8753_dai[1].private_data = private_data; - wm8753_dai[1].pop_wait = pop_wait; - wm8753_dai[1].list = list; + struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec); + + if (wm8753->dai_func < 4) { + if (hifi) + dai->driver = &wm8753_all_dai[wm8753->dai_func << 1]; + else + dai->driver = &wm8753_all_dai[(wm8753->dai_func << 1) + 1]; } - wm8753_dai[0].codec = codec; - wm8753_dai[1].codec = codec; + wm8753_write(codec, WM8753_IOCTL, wm8753->dai_func); }
static void wm8753_work(struct work_struct *work) @@ -1503,19 +1489,14 @@ static void wm8753_work(struct work_struct *work) wm8753_set_bias_level(codec, codec->bias_level); }
-static int wm8753_suspend(struct platform_device *pdev, pm_message_t state) +static int wm8753_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; - wm8753_set_bias_level(codec, SND_SOC_BIAS_OFF); return 0; }
-static int wm8753_resume(struct platform_device *pdev) +static int wm8753_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; @@ -1547,41 +1528,6 @@ static int wm8753_resume(struct platform_device *pdev) return 0; }
-static struct snd_soc_codec *wm8753_codec; - -static int wm8753_probe(struct platform_device *pdev) -{ - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - int ret = 0; - - if (!wm8753_codec) { - dev_err(&pdev->dev, "WM8753 codec not yet registered\n"); - return -EINVAL; - } - - socdev->card->codec = wm8753_codec; - codec = wm8753_codec; - - wm8753_set_dai_mode(codec, 0); - - /* register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret < 0) { - printk(KERN_ERR "wm8753: failed to create pcms\n"); - goto pcm_err; - } - - snd_soc_add_controls(codec, wm8753_snd_controls, - ARRAY_SIZE(wm8753_snd_controls)); - wm8753_add_widgets(codec); - - return 0; - -pcm_err: - return ret; -} - /* * This function forces any delayed work to be queued and run. */ @@ -1601,62 +1547,30 @@ static int run_delayed_work(struct delayed_work *dwork) return ret; }
-/* power down chip */ -static int wm8753_remove(struct platform_device *pdev) +static int wm8753_probe(struct snd_soc_codec *codec) { - 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_wm8753 = { - .probe = wm8753_probe, - .remove = wm8753_remove, - .suspend = wm8753_suspend, - .resume = wm8753_resume, -}; -EXPORT_SYMBOL_GPL(soc_codec_dev_wm8753); + struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec); + int ret = 0, reg;
-static int wm8753_register(struct wm8753_priv *wm8753) -{ - int ret, i; - struct snd_soc_codec *codec = &wm8753->codec; - u16 reg; + codec->bias_level = SND_SOC_BIAS_OFF, + codec->control_data = wm8753->control_data; + INIT_DELAYED_WORK(&codec->delayed_work, wm8753_work);
- if (wm8753_codec) { - dev_err(codec->dev, "Multiple WM8753 devices not supported\n"); - ret = -EINVAL; - goto err; + ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8753->control_type); + if (ret < 0) { + dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); + return ret; }
- mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - codec->name = "WM8753"; - codec->owner = THIS_MODULE; - codec->read = wm8753_read_reg_cache; - codec->write = wm8753_write; - codec->bias_level = SND_SOC_BIAS_STANDBY; - codec->set_bias_level = wm8753_set_bias_level; - codec->dai = wm8753_dai; - codec->num_dai = 2; - codec->reg_cache_size = ARRAY_SIZE(wm8753->reg_cache) + 1; - codec->reg_cache = &wm8753->reg_cache; - snd_soc_codec_set_drvdata(codec, wm8753); - - memcpy(codec->reg_cache, wm8753_reg, sizeof(wm8753->reg_cache)); - INIT_DELAYED_WORK(&codec->delayed_work, wm8753_work); - ret = wm8753_reset(codec); if (ret < 0) { - dev_err(codec->dev, "Failed to issue reset\n"); - goto err; + dev_err(codec->dev, "Failed to issue reset: %d\n", ret); + return ret; }
+ wm8753_set_bias_level(codec, SND_SOC_BIAS_STANDBY); + wm8753->dai_func = 0; + /* charge output caps */ wm8753_set_bias_level(codec, SND_SOC_BIAS_PREPARE); schedule_delayed_work(&codec->delayed_work, @@ -1684,165 +1598,142 @@ static int wm8753_register(struct wm8753_priv *wm8753) reg = wm8753_read_reg_cache(codec, WM8753_RINVOL); wm8753_write(codec, WM8753_RINVOL, reg | 0x0100);
- wm8753_codec = codec; - - for (i = 0; i < ARRAY_SIZE(wm8753_dai); i++) - wm8753_dai[i].dev = codec->dev; - - ret = snd_soc_register_codec(codec); - if (ret != 0) { - dev_err(codec->dev, "Failed to register codec: %d\n", ret); - goto err; - } - - ret = snd_soc_register_dais(&wm8753_dai[0], ARRAY_SIZE(wm8753_dai)); - if (ret != 0) { - dev_err(codec->dev, "Failed to register DAIs: %d\n", ret); - goto err_codec; - } + snd_soc_add_controls(codec, wm8753_snd_controls, + ARRAY_SIZE(wm8753_snd_controls)); + wm8753_add_widgets(codec);
return 0;
-err_codec: run_delayed_work(&codec->delayed_work); - snd_soc_unregister_codec(codec); -err: - kfree(wm8753); return ret; }
-static void wm8753_unregister(struct wm8753_priv *wm8753) +/* power down chip */ +static int wm8753_remove(struct snd_soc_codec *codec) { - wm8753_set_bias_level(&wm8753->codec, SND_SOC_BIAS_OFF); - run_delayed_work(&wm8753->codec.delayed_work); - snd_soc_unregister_dais(&wm8753_dai[0], ARRAY_SIZE(wm8753_dai)); - snd_soc_unregister_codec(&wm8753->codec); - kfree(wm8753); - wm8753_codec = NULL; + run_delayed_work(&codec->delayed_work); + wm8753_set_bias_level(codec, SND_SOC_BIAS_OFF); + + return 0; }
-#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) +struct snd_soc_codec_driver soc_codec_dev_wm8753 = { + .name = "wm8753", + .probe = wm8753_probe, + .remove = wm8753_remove, + .suspend = wm8753_suspend, + .resume = wm8753_resume, + .owner = THIS_MODULE, + .set_bias_level = wm8753_set_bias_level, + .reg_cache_size = sizeof(wm8753_reg), + .reg_word_size = sizeof(u16), + .reg_cache_default = wm8753_reg, +}; +EXPORT_SYMBOL_GPL(soc_codec_dev_wm8753);
-static int wm8753_i2c_probe(struct i2c_client *i2c, - const struct i2c_device_id *id) +#if defined(CONFIG_SPI_MASTER) +static int __devinit wm8753_spi_probe(struct spi_device *spi) { - struct snd_soc_codec *codec; struct wm8753_priv *wm8753; + int ret;
wm8753 = kzalloc(sizeof(struct wm8753_priv), GFP_KERNEL); if (wm8753 == NULL) return -ENOMEM;
- codec = &wm8753->codec; - codec->hw_write = (hw_write_t)i2c_master_send; - codec->control_data = i2c; - i2c_set_clientdata(i2c, wm8753); - - codec->dev = &i2c->dev; + wm8753->control_data = spi; + wm8753->control_type = SND_SOC_SPI; + spi_set_drvdata(spi, wm8753);
- return wm8753_register(wm8753); + ret = snd_soc_register_codec(&spi->dev, spi->chip_select, + &soc_codec_dev_wm8753, wm8753_dai, ARRAY_SIZE(wm8753_dai)); + if (ret < 0) + kfree(wm8753); + return ret; }
-static int wm8753_i2c_remove(struct i2c_client *client) +static int __devexit wm8753_spi_remove(struct spi_device *spi) { - struct wm8753_priv *wm8753 = i2c_get_clientdata(client); - wm8753_unregister(wm8753); - return 0; + snd_soc_unregister_codec(&spi->dev, spi->chip_select); + kfree(spi_get_drvdata(spi)); + return 0; }
-static const struct i2c_device_id wm8753_i2c_id[] = { - { "wm8753", 0 }, - { } -}; -MODULE_DEVICE_TABLE(i2c, wm8753_i2c_id); - -static struct i2c_driver wm8753_i2c_driver = { +static struct spi_driver wm8753_spi_driver = { .driver = { - .name = "wm8753", - .owner = THIS_MODULE, + .name = "wm8753", + .bus = &spi_bus_type, + .owner = THIS_MODULE, }, - .probe = wm8753_i2c_probe, - .remove = wm8753_i2c_remove, - .id_table = wm8753_i2c_id, + .probe = wm8753_spi_probe, + .remove = __devexit_p(wm8753_spi_remove), }; -#endif - -#if defined(CONFIG_SPI_MASTER) -static int wm8753_spi_write(struct spi_device *spi, const char *data, int len) -{ - struct spi_transfer t; - struct spi_message m; - u8 msg[2]; - - if (len <= 0) - return 0; +#endif /* CONFIG_SPI_MASTER */
- msg[0] = data[0]; - msg[1] = data[1]; - - spi_message_init(&m); - memset(&t, 0, (sizeof t)); - - t.tx_buf = &msg[0]; - t.len = len; - - spi_message_add_tail(&t, &m); - spi_sync(spi, &m); - - return len; -} - -static int __devinit wm8753_spi_probe(struct spi_device *spi) +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) +static __devinit int wm8753_i2c_probe(struct i2c_client *i2c, + const struct i2c_device_id *id) { - struct snd_soc_codec *codec; struct wm8753_priv *wm8753; + int ret;
wm8753 = kzalloc(sizeof(struct wm8753_priv), GFP_KERNEL); if (wm8753 == NULL) return -ENOMEM;
- codec = &wm8753->codec; - codec->control_data = spi; - codec->hw_write = (hw_write_t)wm8753_spi_write; - codec->dev = &spi->dev; + i2c_set_clientdata(i2c, wm8753); + wm8753->control_data = i2c; + wm8753->control_type = SND_SOC_I2C;
- dev_set_drvdata(&spi->dev, wm8753); - - return wm8753_register(wm8753); + ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &soc_codec_dev_wm8753, wm8753_dai, ARRAY_SIZE(wm8753_dai)); + if (ret < 0) + kfree(wm8753); + return ret; }
-static int __devexit wm8753_spi_remove(struct spi_device *spi) +static __devexit int wm8753_i2c_remove(struct i2c_client *client) { - struct wm8753_priv *wm8753 = dev_get_drvdata(&spi->dev); - wm8753_unregister(wm8753); + snd_soc_unregister_codec(&client->dev, client->addr); + kfree(i2c_get_clientdata(client)); return 0; }
-static struct spi_driver wm8753_spi_driver = { +static const struct i2c_device_id wm8753_i2c_id[] = { + { "wm8753", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, wm8753_i2c_id); + +static struct i2c_driver wm8753_i2c_driver = { .driver = { - .name = "wm8753", - .bus = &spi_bus_type, - .owner = THIS_MODULE, + .name = "wm8753 I2C Codec", + .owner = THIS_MODULE, }, - .probe = wm8753_spi_probe, - .remove = __devexit_p(wm8753_spi_remove), + .probe = wm8753_i2c_probe, + .remove = __devexit_p(wm8753_i2c_remove), + .id_table = wm8753_i2c_id, }; #endif
static int __init wm8753_modinit(void) { - int ret; + int ret = 0; #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) ret = i2c_add_driver(&wm8753_i2c_driver); - if (ret != 0) - pr_err("Failed to register WM8753 I2C driver: %d\n", ret); + if (ret != 0) { + printk(KERN_ERR "Failed to register wm8753 I2C driver: %d\n", + ret); + } #endif #if defined(CONFIG_SPI_MASTER) ret = spi_register_driver(&wm8753_spi_driver); - if (ret != 0) - pr_err("Failed to register WM8753 SPI driver: %d\n", ret); + if (ret != 0) { + printk(KERN_ERR "Failed to register wm8753 SPI driver: %d\n", + ret); + } #endif - return 0; + return ret; } module_init(wm8753_modinit);
diff --git a/sound/soc/codecs/wm8753.h b/sound/soc/codecs/wm8753.h index 57b2ba2..27a9336 100644 --- a/sound/soc/codecs/wm8753.h +++ b/sound/soc/codecs/wm8753.h @@ -115,7 +115,7 @@ #define WM8753_DAI_HIFI 0 #define WM8753_DAI_VOICE 1
-extern struct snd_soc_dai wm8753_dai[2]; -extern struct snd_soc_codec_device soc_codec_dev_wm8753; +extern struct snd_soc_dai_driver wm8753_dai[2]; +extern struct snd_soc_codec_driver soc_codec_dev_wm8753;
#endif diff --git a/sound/soc/codecs/wm8776.c b/sound/soc/codecs/wm8776.c index 7e4a627..a0ab570 100644 --- a/sound/soc/codecs/wm8776.c +++ b/sound/soc/codecs/wm8776.c @@ -31,20 +31,14 @@
#include "wm8776.h"
-static struct snd_soc_codec *wm8776_codec; -struct snd_soc_codec_device soc_codec_dev_wm8776; - /* codec private data */ struct wm8776_priv { - struct snd_soc_codec codec; + enum snd_soc_control_type control_type; + void *control_data; u16 reg_cache[WM8776_CACHEREGNUM]; int sysclk[2]; };
-#ifdef CONFIG_SPI_MASTER -static int wm8776_spi_write(struct spi_device *spi, const char *data, int len); -#endif - static const u16 wm8776_reg[WM8776_CACHEREGNUM] = { 0x79, 0x79, 0x79, 0xff, 0xff, /* 4 */ 0xff, 0x00, 0x90, 0x00, 0x00, /* 9 */ @@ -358,10 +352,9 @@ static struct snd_soc_dai_ops wm8776_adc_ops = { .set_sysclk = wm8776_set_sysclk, };
-struct snd_soc_dai wm8776_dai[] = { +struct snd_soc_dai_driver wm8776_dai[] = { { .name = "WM8776 Playback", - .id = WM8776_DAI_DAC, .playback = { .stream_name = "Playback", .channels_min = 2, @@ -373,7 +366,6 @@ struct snd_soc_dai wm8776_dai[] = { }, { .name = "WM8776 Capture", - .id = WM8776_DAI_ADC, .capture = { .stream_name = "Capture", .channels_min = 2, @@ -387,20 +379,15 @@ struct snd_soc_dai wm8776_dai[] = { EXPORT_SYMBOL_GPL(wm8776_dai);
#ifdef CONFIG_PM -static int wm8776_suspend(struct platform_device *pdev, pm_message_t state) +static int wm8776_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; - wm8776_set_bias_level(codec, SND_SOC_BIAS_OFF);
return 0; }
-static int wm8776_resume(struct platform_device *pdev) +static int wm8776_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; @@ -423,27 +410,31 @@ static int wm8776_resume(struct platform_device *pdev) #define wm8776_resume NULL #endif
-static int wm8776_probe(struct platform_device *pdev) +static int wm8776_probe(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; + struct wm8776_priv *wm8776 = snd_soc_codec_get_drvdata(codec); int ret = 0;
- if (wm8776_codec == NULL) { - dev_err(&pdev->dev, "Codec device not registered\n"); - return -ENODEV; + codec->control_data = wm8776->control_data; + ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8776->control_type); + if (ret < 0) { + dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); + return ret; }
- socdev->card->codec = wm8776_codec; - codec = wm8776_codec; - - /* register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); + ret = wm8776_reset(codec); if (ret < 0) { - dev_err(codec->dev, "failed to create pcms: %d\n", ret); - goto pcm_err; + dev_err(codec->dev, "Failed to issue reset: %d\n", ret); + return ret; }
+ wm8776_set_bias_level(codec, SND_SOC_BIAS_STANDBY); + + /* Latch the update bits; right channel only since we always + * update both. */ + snd_soc_update_bits(codec, WM8776_HPRVOL, 0x100, 0x100); + snd_soc_update_bits(codec, WM8776_DACRVOL, 0x100, 0x100); + snd_soc_add_controls(codec, wm8776_snd_controls, ARRAY_SIZE(wm8776_snd_controls)); snd_soc_dapm_new_controls(codec, wm8776_dapm_widgets, @@ -451,162 +442,54 @@ static int wm8776_probe(struct platform_device *pdev) snd_soc_dapm_add_routes(codec, routes, ARRAY_SIZE(routes));
return ret; - -pcm_err: - return ret; }
/* power down chip */ -static int wm8776_remove(struct platform_device *pdev) +static int wm8776_remove(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - - snd_soc_free_pcms(socdev); - snd_soc_dapm_free(socdev); - + wm8776_set_bias_level(codec, SND_SOC_BIAS_OFF); return 0; }
-struct snd_soc_codec_device soc_codec_dev_wm8776 = { +struct snd_soc_codec_driver soc_codec_dev_wm8776 = { + .name = "wm8776", .probe = wm8776_probe, .remove = wm8776_remove, .suspend = wm8776_suspend, .resume = wm8776_resume, + .owner = THIS_MODULE, + .set_bias_level = wm8776_set_bias_level, + .reg_cache_size = sizeof(wm8776_reg), + .reg_word_size = sizeof(u16), + .reg_cache_default = wm8776_reg, }; EXPORT_SYMBOL_GPL(soc_codec_dev_wm8776);
-static int wm8776_register(struct wm8776_priv *wm8776, - enum snd_soc_control_type control) -{ - int ret, i; - struct snd_soc_codec *codec = &wm8776->codec; - - if (wm8776_codec) { - dev_err(codec->dev, "Another WM8776 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, wm8776); - codec->name = "WM8776"; - codec->owner = THIS_MODULE; - codec->bias_level = SND_SOC_BIAS_OFF; - codec->set_bias_level = wm8776_set_bias_level; - codec->dai = wm8776_dai; - codec->num_dai = ARRAY_SIZE(wm8776_dai); - codec->reg_cache_size = WM8776_CACHEREGNUM; - codec->reg_cache = &wm8776->reg_cache; - - memcpy(codec->reg_cache, wm8776_reg, sizeof(wm8776_reg)); - - ret = snd_soc_codec_set_cache_io(codec, 7, 9, control); - if (ret < 0) { - dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); - goto err; - } - - for (i = 0; i < ARRAY_SIZE(wm8776_dai); i++) - wm8776_dai[i].dev = codec->dev; - - ret = wm8776_reset(codec); - if (ret < 0) { - dev_err(codec->dev, "Failed to issue reset: %d\n", ret); - goto err; - } - - wm8776_set_bias_level(codec, SND_SOC_BIAS_STANDBY); - - /* Latch the update bits; right channel only since we always - * update both. */ - snd_soc_update_bits(codec, WM8776_HPRVOL, 0x100, 0x100); - snd_soc_update_bits(codec, WM8776_DACRVOL, 0x100, 0x100); - - wm8776_codec = codec; - - ret = snd_soc_register_codec(codec); - if (ret != 0) { - dev_err(codec->dev, "Failed to register codec: %d\n", ret); - goto err; - } - - ret = snd_soc_register_dais(wm8776_dai, ARRAY_SIZE(wm8776_dai)); - if (ret != 0) { - dev_err(codec->dev, "Failed to register DAIs: %d\n", ret); - goto err_codec; - } - - return 0; - -err_codec: - snd_soc_unregister_codec(codec); -err: - kfree(wm8776); - return ret; -} - -static void wm8776_unregister(struct wm8776_priv *wm8776) -{ - wm8776_set_bias_level(&wm8776->codec, SND_SOC_BIAS_OFF); - snd_soc_unregister_dais(wm8776_dai, ARRAY_SIZE(wm8776_dai)); - snd_soc_unregister_codec(&wm8776->codec); - kfree(wm8776); - wm8776_codec = NULL; -} - #if defined(CONFIG_SPI_MASTER) -static int wm8776_spi_write(struct spi_device *spi, const char *data, int len) -{ - struct spi_transfer t; - struct spi_message m; - u8 msg[2]; - - if (len <= 0) - return 0; - - msg[0] = data[0]; - msg[1] = data[1]; - - spi_message_init(&m); - memset(&t, 0, (sizeof t)); - - t.tx_buf = &msg[0]; - t.len = len; - - spi_message_add_tail(&t, &m); - spi_sync(spi, &m); - - return len; -} - static int __devinit wm8776_spi_probe(struct spi_device *spi) { - struct snd_soc_codec *codec; struct wm8776_priv *wm8776; + int ret;
wm8776 = kzalloc(sizeof(struct wm8776_priv), GFP_KERNEL); if (wm8776 == NULL) return -ENOMEM;
- codec = &wm8776->codec; - codec->control_data = spi; - codec->hw_write = (hw_write_t)wm8776_spi_write; - codec->dev = &spi->dev; + wm8776->control_data = spi; + wm8776->control_type = SND_SOC_SPI; + spi_set_drvdata(spi, wm8776);
- dev_set_drvdata(&spi->dev, wm8776); - - return wm8776_register(wm8776, SND_SOC_SPI); + ret = snd_soc_register_codec(&spi->dev, spi->chip_select, + &soc_codec_dev_wm8776, wm8776_dai, ARRAY_SIZE(wm8776_dai)); + if (ret < 0) + kfree(wm8776); + return ret; }
static int __devexit wm8776_spi_remove(struct spi_device *spi) { - struct wm8776_priv *wm8776 = dev_get_drvdata(&spi->dev); - - wm8776_unregister(wm8776); - + snd_soc_unregister_codec(&spi->dev, spi->chip_select); + kfree(spi_get_drvdata(spi)); return 0; }
@@ -626,27 +509,27 @@ static __devinit int wm8776_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct wm8776_priv *wm8776; - struct snd_soc_codec *codec; + int ret;
wm8776 = kzalloc(sizeof(struct wm8776_priv), GFP_KERNEL); if (wm8776 == NULL) return -ENOMEM;
- codec = &wm8776->codec; - codec->hw_write = (hw_write_t)i2c_master_send; - i2c_set_clientdata(i2c, wm8776); - codec->control_data = i2c; - - codec->dev = &i2c->dev; + wm8776->control_data = i2c; + wm8776->control_type = SND_SOC_I2C;
- return wm8776_register(wm8776, SND_SOC_I2C); + ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &soc_codec_dev_wm8776, wm8776_dai, ARRAY_SIZE(wm8776_dai)); + if (ret < 0) + kfree(wm8776); + return ret; }
static __devexit int wm8776_i2c_remove(struct i2c_client *client) { - struct wm8776_priv *wm8776 = i2c_get_clientdata(client); - wm8776_unregister(wm8776); + snd_soc_unregister_codec(&client->dev, client->addr); + kfree(i2c_get_clientdata(client)); return 0; }
@@ -658,7 +541,7 @@ MODULE_DEVICE_TABLE(i2c, wm8776_i2c_id);
static struct i2c_driver wm8776_i2c_driver = { .driver = { - .name = "wm8776", + .name = "wm8776 I2C Codec", .owner = THIS_MODULE, }, .probe = wm8776_i2c_probe, @@ -669,22 +552,22 @@ static struct i2c_driver wm8776_i2c_driver = {
static int __init wm8776_modinit(void) { - int ret; + int ret = 0; #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) ret = i2c_add_driver(&wm8776_i2c_driver); if (ret != 0) { - printk(KERN_ERR "Failed to register WM8776 I2C driver: %d\n", + printk(KERN_ERR "Failed to register wm8776 I2C driver: %d\n", ret); } #endif #if defined(CONFIG_SPI_MASTER) ret = spi_register_driver(&wm8776_spi_driver); if (ret != 0) { - printk(KERN_ERR "Failed to register WM8776 SPI driver: %d\n", + printk(KERN_ERR "Failed to register wm8776 SPI driver: %d\n", ret); } #endif - return 0; + return ret; } module_init(wm8776_modinit);
diff --git a/sound/soc/codecs/wm8776.h b/sound/soc/codecs/wm8776.h index 6606d25..9780e3a 100644 --- a/sound/soc/codecs/wm8776.h +++ b/sound/soc/codecs/wm8776.h @@ -45,7 +45,7 @@ #define WM8776_DAI_DAC 0 #define WM8776_DAI_ADC 1
-extern struct snd_soc_dai wm8776_dai[]; -extern struct snd_soc_codec_device soc_codec_dev_wm8776; +extern struct snd_soc_dai_driver wm8776_dai[]; +extern struct snd_soc_codec_driver soc_codec_dev_wm8776;
#endif
Moved to Wolfson CODECs multi-component model.
This patch changes the probe() and remove() of the CODEC drivers as follows:-
o Make CODEC driver a platform device (non MFD codecs only) o Moved all struct snd_soc_codec list, mutex, etc initialiasation to core. o Removed all static codec pointers (drivers now support > 1 codec dev) o snd_soc_register_pcms() now done by core. o snd_soc_register_dai() folded into snd_soc_register_codec(). o codec cache can now be malloc()ed by core.
Signed-off-by: Liam Girdwood lrg@slimlogic.co.uk --- sound/soc/codecs/wm8900.c | 251 +++++++++++++++++++++--------------------- sound/soc/codecs/wm8900.h | 4 +- sound/soc/codecs/wm8903.c | 268 ++++++++++++++++---------------------------- sound/soc/codecs/wm8903.h | 4 +- sound/soc/codecs/wm8904.c | 202 ++++++++++------------------------ sound/soc/codecs/wm8904.h | 4 +- sound/soc/codecs/wm8955.c | 182 ++++++++---------------------- sound/soc/codecs/wm8955.h | 4 +- 8 files changed, 340 insertions(+), 579 deletions(-)
diff --git a/sound/soc/codecs/wm8900.c b/sound/soc/codecs/wm8900.c index 5da17a7..8d92820 100644 --- a/sound/soc/codecs/wm8900.c +++ b/sound/soc/codecs/wm8900.c @@ -23,6 +23,7 @@ #include <linux/delay.h> #include <linux/pm.h> #include <linux/i2c.h> +#include <linux/spi/spi.h> #include <linux/platform_device.h> #include <linux/slab.h> #include <sound/core.h> @@ -137,11 +138,9 @@
#define WM8900_LRC_MASK 0xfc00
-struct snd_soc_codec_device soc_codec_dev_wm8900; - struct wm8900_priv { - struct snd_soc_codec codec; - + enum snd_soc_control_type control_type; + void *control_data; u16 reg_cache[WM8900_MAXREG];
u32 fll_in; /* FLL input frequency */ @@ -627,8 +626,7 @@ static int wm8900_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; u16 reg;
reg = snd_soc_read(codec, WM8900_REG_AUDIO1) & ~0x60; @@ -1015,7 +1013,7 @@ static struct snd_soc_dai_ops wm8900_dai_ops = { .digital_mute = wm8900_digital_mute, };
-struct snd_soc_dai wm8900_dai = { +struct snd_soc_dai_driver wm8900_dai = { .name = "WM8900 HiFi", .playback = { .stream_name = "HiFi Playback", @@ -1128,10 +1126,8 @@ static int wm8900_set_bias_level(struct snd_soc_codec *codec, return 0; }
-static int wm8900_suspend(struct platform_device *pdev, pm_message_t state) +static int wm8900_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; struct wm8900_priv *wm8900 = snd_soc_codec_get_drvdata(codec); int fll_out = wm8900->fll_out; int fll_in = wm8900->fll_in; @@ -1140,7 +1136,7 @@ static int wm8900_suspend(struct platform_device *pdev, pm_message_t state) /* Stop the FLL in an orderly fashion */ ret = wm8900_set_fll(codec, 0, 0, 0); if (ret != 0) { - dev_err(&pdev->dev, "Failed to stop FLL\n"); + dev_err(codec->dev, "Failed to stop FLL\n"); return ret; }
@@ -1152,10 +1148,8 @@ static int wm8900_suspend(struct platform_device *pdev, pm_message_t state) return 0; }
-static int wm8900_resume(struct platform_device *pdev) +static int wm8900_resume(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; struct wm8900_priv *wm8900 = snd_soc_codec_get_drvdata(codec); u16 *cache; int i, ret; @@ -1176,7 +1170,7 @@ static int wm8900_resume(struct platform_device *pdev)
ret = wm8900_set_fll(codec, 0, fll_in, fll_out); if (ret != 0) { - dev_err(&pdev->dev, "Failed to restart FLL\n"); + dev_err(codec->dev, "Failed to restart FLL\n"); return ret; } } @@ -1186,60 +1180,33 @@ static int wm8900_resume(struct platform_device *pdev) snd_soc_write(codec, i, cache[i]); kfree(cache); } else - dev_err(&pdev->dev, "Unable to allocate register cache\n"); + dev_err(codec->dev, "Unable to allocate register cache\n");
return 0; }
-static struct snd_soc_codec *wm8900_codec; - -static __devinit int wm8900_i2c_probe(struct i2c_client *i2c, - const struct i2c_device_id *id) +static int wm8900_probe(struct snd_soc_codec *codec) { - struct wm8900_priv *wm8900; - struct snd_soc_codec *codec; - unsigned int reg; - int ret; - - wm8900 = kzalloc(sizeof(struct wm8900_priv), GFP_KERNEL); - if (wm8900 == NULL) - return -ENOMEM; + struct wm8900_priv *wm8900 = snd_soc_codec_get_drvdata(codec); + int ret = 0, reg;
- codec = &wm8900->codec; - snd_soc_codec_set_drvdata(codec, wm8900); - codec->reg_cache = &wm8900->reg_cache[0]; - codec->reg_cache_size = WM8900_MAXREG; - - mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - codec->name = "WM8900"; - codec->owner = THIS_MODULE; - codec->dai = &wm8900_dai; - codec->num_dai = 1; - codec->control_data = i2c; - codec->set_bias_level = wm8900_set_bias_level; - codec->volatile_register = wm8900_volatile_register; - codec->dev = &i2c->dev; - - ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_I2C); + codec->control_data = wm8900->control_data; + ret = snd_soc_codec_set_cache_io(codec, 8, 16, wm8900->control_type); if (ret != 0) { - dev_err(&i2c->dev, "Failed to set cache I/O: %d\n", ret); - goto err; + dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); + return ret; }
reg = snd_soc_read(codec, WM8900_REG_ID); if (reg != 0x8900) { - dev_err(&i2c->dev, "Device is not a WM8900 - ID %x\n", reg); - ret = -ENODEV; - goto err; + dev_err(codec->dev, "Device is not a WM8900 - ID %x\n", reg); + return -ENODEV; }
/* Read back from the chip */ reg = snd_soc_read(codec, WM8900_REG_POWER1); reg = (reg >> 12) & 0xf; - dev_info(&i2c->dev, "WM8900 revision %d\n", reg); + dev_info(codec->dev, "WM8900 revision %d\n", reg);
wm8900_reset(codec);
@@ -1271,43 +1238,100 @@ static __devinit int wm8900_i2c_probe(struct i2c_client *i2c, /* Set the DAC and mixer output bias */ snd_soc_write(codec, WM8900_REG_OUTBIASCTL, 0x81);
- wm8900_dai.dev = &i2c->dev; + snd_soc_add_controls(codec, wm8900_snd_controls, + ARRAY_SIZE(wm8900_snd_controls)); + wm8900_add_widgets(codec);
- wm8900_codec = codec; + return 0; +}
- ret = snd_soc_register_codec(codec); - if (ret != 0) { - dev_err(&i2c->dev, "Failed to register codec: %d\n", ret); - goto err; - } +/* power down chip */ +static int wm8900_remove(struct snd_soc_codec *codec) +{ + wm8900_set_bias_level(codec, SND_SOC_BIAS_OFF); + return 0; +}
- ret = snd_soc_register_dai(&wm8900_dai); - if (ret != 0) { - dev_err(&i2c->dev, "Failed to register DAI: %d\n", ret); - goto err_codec; - } +struct snd_soc_codec_driver soc_codec_dev_wm8900 = { + .name = "wm8900", + .probe = wm8900_probe, + .remove = wm8900_remove, + .suspend = wm8900_suspend, + .resume = wm8900_resume, + .owner = THIS_MODULE, + .set_bias_level = wm8900_set_bias_level, + .volatile_register = wm8900_volatile_register, + .reg_cache_size = sizeof(wm8900_reg_defaults), + .reg_word_size = sizeof(u16), + .reg_cache_default = wm8900_reg_defaults, +}; +EXPORT_SYMBOL_GPL(soc_codec_dev_wm8900);
- return ret; +#if defined(CONFIG_SPI_MASTER) +static int __devinit wm8900_spi_probe(struct spi_device *spi) +{ + struct wm8900_priv *wm8900; + int ret; + + wm8900 = kzalloc(sizeof(struct wm8900_priv), GFP_KERNEL); + if (wm8900 == NULL) + return -ENOMEM; + + wm8900->control_data = spi; + wm8900->control_type = SND_SOC_SPI; + spi_set_drvdata(spi, wm8900);
-err_codec: - snd_soc_unregister_codec(codec); -err: - kfree(wm8900); - wm8900_codec = NULL; + ret = snd_soc_register_codec(&spi->dev, spi->chip_select, + &soc_codec_dev_wm8900, &wm8900_dai, 1); + if (ret < 0) + kfree(wm8900); return ret; }
-static __devexit int wm8900_i2c_remove(struct i2c_client *client) +static int __devexit wm8900_spi_remove(struct spi_device *spi) { - snd_soc_unregister_dai(&wm8900_dai); - snd_soc_unregister_codec(wm8900_codec); + snd_soc_unregister_codec(&spi->dev, spi->chip_select); + kfree(spi_get_drvdata(spi)); + return 0; +}
- wm8900_set_bias_level(wm8900_codec, SND_SOC_BIAS_OFF); +static struct spi_driver wm8900_spi_driver = { + .driver = { + .name = "wm8900", + .bus = &spi_bus_type, + .owner = THIS_MODULE, + }, + .probe = wm8900_spi_probe, + .remove = __devexit_p(wm8900_spi_remove), +}; +#endif /* CONFIG_SPI_MASTER */ + +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) +static __devinit int wm8900_i2c_probe(struct i2c_client *i2c, + const struct i2c_device_id *id) +{ + struct wm8900_priv *wm8900; + int ret; + + wm8900 = kzalloc(sizeof(struct wm8900_priv), GFP_KERNEL); + if (wm8900 == NULL) + return -ENOMEM;
- wm8900_dai.dev = NULL; - kfree(snd_soc_codec_get_drvdata(wm8900_codec)); - wm8900_codec = NULL; + i2c_set_clientdata(i2c, wm8900); + wm8900->control_data = i2c; + wm8900->control_type = SND_SOC_I2C;
+ ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &soc_codec_dev_wm8900, &wm8900_dai, 1); + if (ret < 0) + kfree(wm8900); + return ret; +} + +static __devexit int wm8900_i2c_remove(struct i2c_client *client) +{ + snd_soc_unregister_codec(&client->dev, client->addr); + kfree(i2c_get_clientdata(client)); return 0; }
@@ -1319,71 +1343,44 @@ MODULE_DEVICE_TABLE(i2c, wm8900_i2c_id);
static struct i2c_driver wm8900_i2c_driver = { .driver = { - .name = "WM8900", + .name = "wm8900 I2C Codec", .owner = THIS_MODULE, }, - .probe = wm8900_i2c_probe, - .remove = __devexit_p(wm8900_i2c_remove), + .probe = wm8900_i2c_probe, + .remove = __devexit_p(wm8900_i2c_remove), .id_table = wm8900_i2c_id, }; +#endif
-static int wm8900_probe(struct platform_device *pdev) +static int __init wm8900_modinit(void) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; int ret = 0; - - if (!wm8900_codec) { - dev_err(&pdev->dev, "I2C client not yet instantiated\n"); - return -ENODEV; +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) + ret = i2c_add_driver(&wm8900_i2c_driver); + if (ret != 0) { + printk(KERN_ERR "Failed to register wm8900 I2C driver: %d\n", + ret); } - - codec = wm8900_codec; - socdev->card->codec = codec; - - /* Register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret < 0) { - dev_err(&pdev->dev, "Failed to register new PCMs\n"); - goto pcm_err; +#endif +#if defined(CONFIG_SPI_MASTER) + ret = spi_register_driver(&wm8900_spi_driver); + if (ret != 0) { + printk(KERN_ERR "Failed to register wm8900 SPI driver: %d\n", + ret); } - - snd_soc_add_controls(codec, wm8900_snd_controls, - ARRAY_SIZE(wm8900_snd_controls)); - wm8900_add_widgets(codec); - -pcm_err: +#endif return ret; } - -/* power down chip */ -static int wm8900_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_wm8900 = { - .probe = wm8900_probe, - .remove = wm8900_remove, - .suspend = wm8900_suspend, - .resume = wm8900_resume, -}; -EXPORT_SYMBOL_GPL(soc_codec_dev_wm8900); - -static int __init wm8900_modinit(void) -{ - return i2c_add_driver(&wm8900_i2c_driver); -} module_init(wm8900_modinit);
static void __exit wm8900_exit(void) { +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) i2c_del_driver(&wm8900_i2c_driver); +#endif +#if defined(CONFIG_SPI_MASTER) + spi_unregister_driver(&wm8900_spi_driver); +#endif } module_exit(wm8900_exit);
diff --git a/sound/soc/codecs/wm8900.h b/sound/soc/codecs/wm8900.h index fd15007..f5fd842 100644 --- a/sound/soc/codecs/wm8900.h +++ b/sound/soc/codecs/wm8900.h @@ -52,7 +52,7 @@ #define WM8900_DAC_CLKDIV_5_5 0x14 #define WM8900_DAC_CLKDIV_6 0x18
-extern struct snd_soc_dai wm8900_dai; -extern struct snd_soc_codec_device soc_codec_dev_wm8900; +extern struct snd_soc_dai_driver wm8900_dai; +extern struct snd_soc_codec_driver soc_codec_dev_wm8900;
#endif diff --git a/sound/soc/codecs/wm8903.c b/sound/soc/codecs/wm8903.c index bf08282..3dec67f 100644 --- a/sound/soc/codecs/wm8903.c +++ b/sound/soc/codecs/wm8903.c @@ -213,10 +213,12 @@ static u16 wm8903_reg_defaults[] = { };
struct wm8903_priv { - struct snd_soc_codec codec; + u16 reg_cache[ARRAY_SIZE(wm8903_reg_defaults)];
int sysclk; + struct i2c_client *control_data; + int irq;
/* Reference counts */ int class_w_users; @@ -252,7 +254,6 @@ static int wm8903_volatile_register(unsigned int reg) static int wm8903_run_sequence(struct snd_soc_codec *codec, unsigned int start) { u16 reg[5]; - struct i2c_client *i2c = codec->control_data; struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
BUG_ON(start > 48); @@ -262,7 +263,7 @@ static int wm8903_run_sequence(struct snd_soc_codec *codec, unsigned int start) snd_soc_write(codec, WM8903_WRITE_SEQUENCER_0, reg[0] | WM8903_WSEQ_ENA);
- dev_dbg(&i2c->dev, "Starting sequence at %d\n", start); + dev_dbg(codec->dev, "Starting sequence at %d\n", start);
snd_soc_write(codec, WM8903_WRITE_SEQUENCER_3, start | WM8903_WSEQ_START); @@ -277,7 +278,7 @@ static int wm8903_run_sequence(struct snd_soc_codec *codec, unsigned int start) reg[4] = snd_soc_read(codec, WM8903_WRITE_SEQUENCER_4); } while (reg[4] & WM8903_WSEQ_BUSY);
- dev_dbg(&i2c->dev, "Sequence complete\n"); + dev_dbg(codec->dev, "Sequence complete\n");
/* Disable the sequencer again if we enabled it */ snd_soc_write(codec, WM8903_WRITE_SEQUENCER_0, reg[0]); @@ -422,7 +423,6 @@ static int wm8903_class_w_put(struct snd_kcontrol *kcontrol, struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol); struct snd_soc_codec *codec = widget->codec; struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec); - struct i2c_client *i2c = codec->control_data; u16 reg; int ret;
@@ -431,7 +431,7 @@ static int wm8903_class_w_put(struct snd_kcontrol *kcontrol, /* Turn it off if we're about to enable bypass */ if (ucontrol->value.integer.value[0]) { if (wm8903->class_w_users == 0) { - dev_dbg(&i2c->dev, "Disabling Class W\n"); + dev_dbg(codec->dev, "Disabling Class W\n"); snd_soc_write(codec, WM8903_CLASS_W_0, reg & ~(WM8903_CP_DYN_FREQ | WM8903_CP_DYN_V)); } @@ -444,14 +444,14 @@ static int wm8903_class_w_put(struct snd_kcontrol *kcontrol, /* If we've just disabled the last bypass path turn Class W on */ if (!ucontrol->value.integer.value[0]) { if (wm8903->class_w_users == 1) { - dev_dbg(&i2c->dev, "Enabling Class W\n"); + dev_dbg(codec->dev, "Enabling Class W\n"); snd_soc_write(codec, WM8903_CLASS_W_0, reg | WM8903_CP_DYN_FREQ | WM8903_CP_DYN_V); } wm8903->class_w_users--; }
- dev_dbg(&i2c->dev, "Bypass use count now %d\n", + dev_dbg(codec->dev, "Bypass use count now %d\n", wm8903->class_w_users);
return ret; @@ -935,7 +935,6 @@ static int wm8903_add_widgets(struct snd_soc_codec *codec) static int wm8903_set_bias_level(struct snd_soc_codec *codec, enum snd_soc_bias_level level) { - struct i2c_client *i2c = codec->control_data; u16 reg, reg2;
switch (level) { @@ -974,7 +973,7 @@ static int wm8903_set_bias_level(struct snd_soc_codec *codec, /* By default no bypass paths are enabled so * enable Class W support. */ - dev_dbg(&i2c->dev, "Enabling Class W\n"); + dev_dbg(codec->dev, "Enabling Class W\n"); snd_soc_write(codec, WM8903_CLASS_W_0, reg | WM8903_CP_DYN_FREQ | WM8903_CP_DYN_V); } @@ -1228,10 +1227,8 @@ static int wm8903_startup(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 wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec); - struct i2c_client *i2c = codec->control_data; struct snd_pcm_runtime *master_runtime;
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) @@ -1245,7 +1242,7 @@ static int wm8903_startup(struct snd_pcm_substream *substream, if (wm8903->master_substream) { master_runtime = wm8903->master_substream->runtime;
- dev_dbg(&i2c->dev, "Constraining to %d bits\n", + dev_dbg(codec->dev, "Constraining to %d bits\n", master_runtime->sample_bits);
snd_pcm_hw_constraint_minmax(substream->runtime, @@ -1264,8 +1261,7 @@ static void wm8903_shutdown(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 wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) @@ -1284,10 +1280,8 @@ static int wm8903_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 wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec); - struct i2c_client *i2c = codec->control_data; int fs = params_rate(params); int bclk; int bclk_div; @@ -1306,7 +1300,7 @@ static int wm8903_hw_params(struct snd_pcm_substream *substream, u16 dac_digital1 = snd_soc_read(codec, WM8903_DAC_DIGITAL_1);
if (substream == wm8903->slave_substream) { - dev_dbg(&i2c->dev, "Ignoring hw_params for slave substream\n"); + dev_dbg(codec->dev, "Ignoring hw_params for slave substream\n"); return 0; }
@@ -1332,7 +1326,7 @@ static int wm8903_hw_params(struct snd_pcm_substream *substream, switch (sample_rates[dsp_config].rate) { case 88200: case 96000: - dev_err(&i2c->dev, "%dHz unsupported by ADC\n", + dev_err(codec->dev, "%dHz unsupported by ADC\n", fs); return -EINVAL;
@@ -1340,7 +1334,7 @@ static int wm8903_hw_params(struct snd_pcm_substream *substream, break; }
- dev_dbg(&i2c->dev, "DSP fs = %dHz\n", sample_rates[dsp_config].rate); + dev_dbg(codec->dev, "DSP fs = %dHz\n", sample_rates[dsp_config].rate); clock1 &= ~WM8903_SAMPLE_RATE_MASK; clock1 |= sample_rates[dsp_config].value;
@@ -1366,7 +1360,7 @@ static int wm8903_hw_params(struct snd_pcm_substream *substream, return -EINVAL; }
- dev_dbg(&i2c->dev, "MCLK = %dHz, target sample rate = %dHz\n", + dev_dbg(codec->dev, "MCLK = %dHz, target sample rate = %dHz\n", wm8903->sysclk, fs);
/* We may not have an MCLK which allows us to generate exactly @@ -1401,12 +1395,12 @@ static int wm8903_hw_params(struct snd_pcm_substream *substream, clock1 |= clk_sys_ratios[clk_config].rate << WM8903_CLK_SYS_RATE_SHIFT; clock1 |= clk_sys_ratios[clk_config].mode << WM8903_CLK_SYS_MODE_SHIFT;
- dev_dbg(&i2c->dev, "CLK_SYS_RATE=%x, CLK_SYS_MODE=%x div=%d\n", + dev_dbg(codec->dev, "CLK_SYS_RATE=%x, CLK_SYS_MODE=%x div=%d\n", clk_sys_ratios[clk_config].rate, clk_sys_ratios[clk_config].mode, clk_sys_ratios[clk_config].div);
- dev_dbg(&i2c->dev, "Actual CLK_SYS = %dHz\n", clk_sys); + dev_dbg(codec->dev, "Actual CLK_SYS = %dHz\n", clk_sys);
/* We may not get quite the right frequency if using * approximate clocks so look for the closest match that is @@ -1428,7 +1422,7 @@ static int wm8903_hw_params(struct snd_pcm_substream *substream, aif2 &= ~WM8903_BCLK_DIV_MASK; aif3 &= ~WM8903_LRCLK_RATE_MASK;
- dev_dbg(&i2c->dev, "BCLK ratio %d for %dHz - actual BCLK = %dHz\n", + dev_dbg(codec->dev, "BCLK ratio %d for %dHz - actual BCLK = %dHz\n", bclk_divs[bclk_div].ratio / 10, bclk, (clk_sys * 10) / bclk_divs[bclk_div].ratio);
@@ -1504,8 +1498,8 @@ EXPORT_SYMBOL_GPL(wm8903_mic_detect);
static irqreturn_t wm8903_irq(int irq, void *data) { - struct wm8903_priv *wm8903 = data; - struct snd_soc_codec *codec = &wm8903->codec; + struct snd_soc_codec *codec = data; + struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec); int mic_report; int int_pol; int int_val = 0; @@ -1586,7 +1580,7 @@ static struct snd_soc_dai_ops wm8903_dai_ops = { .set_sysclk = wm8903_set_dai_sysclk, };
-struct snd_soc_dai wm8903_dai = { +struct snd_soc_dai_driver wm8903_dai = { .name = "WM8903", .playback = { .stream_name = "Playback", @@ -1607,21 +1601,15 @@ struct snd_soc_dai wm8903_dai = { }; EXPORT_SYMBOL_GPL(wm8903_dai);
-static int wm8903_suspend(struct platform_device *pdev, pm_message_t state) +static int wm8903_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; - wm8903_set_bias_level(codec, SND_SOC_BIAS_OFF);
return 0; }
-static int wm8903_resume(struct platform_device *pdev) +static int wm8903_resume(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - struct i2c_client *i2c = codec->control_data; int i; u16 *reg_cache = codec->reg_cache; u16 *tmp_cache = kmemdup(reg_cache, sizeof(wm8903_reg_defaults), @@ -1637,65 +1625,38 @@ static int wm8903_resume(struct platform_device *pdev) snd_soc_write(codec, i, tmp_cache[i]); kfree(tmp_cache); } else { - dev_err(&i2c->dev, "Failed to allocate temporary cache\n"); + dev_err(codec->dev, "Failed to allocate temporary cache\n"); }
return 0; }
-static struct snd_soc_codec *wm8903_codec; - -static __devinit int wm8903_i2c_probe(struct i2c_client *i2c, - const struct i2c_device_id *id) +static int wm8903_probe(struct snd_soc_codec *codec) { - struct wm8903_platform_data *pdata = dev_get_platdata(&i2c->dev); - struct wm8903_priv *wm8903; - struct snd_soc_codec *codec; + struct wm8903_platform_data *pdata = dev_get_platdata(codec->dev); + struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec); int ret, i; int trigger, irq_pol; u16 val;
- wm8903 = kzalloc(sizeof(struct wm8903_priv), GFP_KERNEL); - if (wm8903 == NULL) - return -ENOMEM; - - codec = &wm8903->codec; - - mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - codec->dev = &i2c->dev; - codec->name = "WM8903"; - codec->owner = THIS_MODULE; - codec->bias_level = SND_SOC_BIAS_OFF; - codec->set_bias_level = wm8903_set_bias_level; - codec->dai = &wm8903_dai; - codec->num_dai = 1; - codec->reg_cache_size = ARRAY_SIZE(wm8903->reg_cache); - codec->reg_cache = &wm8903->reg_cache[0]; - snd_soc_codec_set_drvdata(codec, wm8903); - codec->volatile_register = wm8903_volatile_register; init_completion(&wm8903->wseq); - - i2c_set_clientdata(i2c, codec); - codec->control_data = i2c; + codec->control_data = wm8903->control_data;
ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_I2C); if (ret != 0) { - dev_err(&i2c->dev, "Failed to set cache I/O: %d\n", ret); - goto err; + dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); + return ret; }
val = snd_soc_read(codec, WM8903_SW_RESET_AND_ID); if (val != wm8903_reg_defaults[WM8903_SW_RESET_AND_ID]) { - dev_err(&i2c->dev, + dev_err(codec->dev, "Device with ID register %x is not a WM8903\n", val); return -ENODEV; }
val = snd_soc_read(codec, WM8903_REVISION_NUMBER); - dev_info(&i2c->dev, "WM8903 revision %d\n", + dev_info(codec->dev, "WM8903 revision %d\n", val & WM8903_CHIP_REV_MASK);
wm8903_reset(codec); @@ -1721,7 +1682,7 @@ static __devinit int wm8903_i2c_probe(struct i2c_client *i2c, wm8903->mic_delay = pdata->micdet_delay; } - if (i2c->irq) { + if (wm8903->irq) { if (pdata && pdata->irq_active_low) { trigger = IRQF_TRIGGER_LOW; irq_pol = WM8903_IRQ_POL; @@ -1733,13 +1694,13 @@ static __devinit int wm8903_i2c_probe(struct i2c_client *i2c, snd_soc_update_bits(codec, WM8903_INTERRUPT_CONTROL, WM8903_IRQ_POL, irq_pol); - ret = request_threaded_irq(i2c->irq, NULL, wm8903_irq, + ret = request_threaded_irq(wm8903->irq, NULL, wm8903_irq, trigger | IRQF_ONESHOT, - "wm8903", wm8903); + "wm8903", codec); if (ret != 0) { - dev_err(&i2c->dev, "Failed to request IRQ: %d\n", + dev_err(codec->dev, "Failed to request IRQ: %d\n", ret); - goto err; + return ret; }
/* Enable write sequencer interrupts */ @@ -1781,133 +1742,100 @@ static __devinit int wm8903_i2c_probe(struct i2c_client *i2c, val |= WM8903_DAC_MUTEMODE; snd_soc_write(codec, WM8903_DAC_DIGITAL_1, val);
- wm8903_dai.dev = &i2c->dev; - wm8903_codec = codec; - - ret = snd_soc_register_codec(codec); - if (ret != 0) { - dev_err(&i2c->dev, "Failed to register codec: %d\n", ret); - goto err_irq; - } - - ret = snd_soc_register_dai(&wm8903_dai); - if (ret != 0) { - dev_err(&i2c->dev, "Failed to register DAI: %d\n", ret); - goto err_codec; - } - - return ret; + snd_soc_add_controls(codec, wm8903_snd_controls, + ARRAY_SIZE(wm8903_snd_controls)); + wm8903_add_widgets(codec);
-err_codec: - snd_soc_unregister_codec(codec); -err_irq: - if (i2c->irq) - free_irq(i2c->irq, wm8903); -err: - wm8903_codec = NULL; - kfree(wm8903); return ret; }
-static __devexit int wm8903_i2c_remove(struct i2c_client *client) +/* power down chip */ +static int wm8903_remove(struct snd_soc_codec *codec) { - struct snd_soc_codec *codec = i2c_get_clientdata(client); - struct wm8903_priv *priv = snd_soc_codec_get_drvdata(codec); + wm8903_set_bias_level(codec, SND_SOC_BIAS_OFF); + return 0; +}
- snd_soc_unregister_dai(&wm8903_dai); - snd_soc_unregister_codec(codec); +struct snd_soc_codec_driver soc_codec_dev_wm8903 = { + .name = "wm8903", + .owner = THIS_MODULE, + .probe = wm8903_probe, + .remove = wm8903_remove, + .suspend = wm8903_suspend, + .resume = wm8903_resume, + .set_bias_level = wm8903_set_bias_level, + .reg_cache_size = ARRAY_SIZE(wm8903_reg_defaults), + .reg_word_size = sizeof(u16), + .reg_cache_default = wm8903_reg_defaults, + .volatile_register = wm8903_volatile_register, +}; +EXPORT_SYMBOL_GPL(soc_codec_dev_wm8903);
- wm8903_set_bias_level(codec, SND_SOC_BIAS_OFF); +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) +static __devinit int wm8903_i2c_probe(struct i2c_client *i2c, + const struct i2c_device_id *id) +{ + struct wm8903_priv *wm8903; + int ret;
- if (client->irq) - free_irq(client->irq, priv); + wm8903 = kzalloc(sizeof(struct wm8903_priv), GFP_KERNEL); + if (wm8903 == NULL) + return -ENOMEM;
- kfree(priv); + i2c_set_clientdata(i2c, wm8903); + wm8903->control_data = i2c; + wm8903->irq = i2c->irq;
- wm8903_codec = NULL; - wm8903_dai.dev = NULL; + ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &soc_codec_dev_wm8903, &wm8903_dai, 1); + if (ret < 0) + kfree(wm8903); + return ret; +}
+static __devexit int wm8903_i2c_remove(struct i2c_client *client) +{ + snd_soc_unregister_codec(&client->dev, client->addr); + kfree(i2c_get_clientdata(client)); return 0; }
-/* i2c codec control layer */ static const struct i2c_device_id wm8903_i2c_id[] = { - { "wm8903", 0 }, - { } + { "wm8903", 0 }, + { } }; MODULE_DEVICE_TABLE(i2c, wm8903_i2c_id);
static struct i2c_driver wm8903_i2c_driver = { .driver = { - .name = "WM8903", + .name = "wm8903 I2C Codec", .owner = THIS_MODULE, }, - .probe = wm8903_i2c_probe, - .remove = __devexit_p(wm8903_i2c_remove), + .probe = wm8903_i2c_probe, + .remove = __devexit_p(wm8903_i2c_remove), .id_table = wm8903_i2c_id, }; +#endif
-static int wm8903_probe(struct platform_device *pdev) +static int __init wm8903_modinit(void) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); int ret = 0; - - if (!wm8903_codec) { - dev_err(&pdev->dev, "I2C device not yet probed\n"); - goto err; - } - - socdev->card->codec = wm8903_codec; - - /* register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret < 0) { - dev_err(&pdev->dev, "failed to create pcms\n"); - goto err; +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) + ret = i2c_add_driver(&wm8903_i2c_driver); + if (ret != 0) { + printk(KERN_ERR "Failed to register wm8903 I2C driver: %d\n", + ret); } - - snd_soc_add_controls(socdev->card->codec, wm8903_snd_controls, - ARRAY_SIZE(wm8903_snd_controls)); - wm8903_add_widgets(socdev->card->codec); - - return ret; - -err: +#endif return ret; } - -/* power down chip */ -static int wm8903_remove(struct platform_device *pdev) -{ - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - - if (codec->control_data) - wm8903_set_bias_level(codec, SND_SOC_BIAS_OFF); - - snd_soc_free_pcms(socdev); - snd_soc_dapm_free(socdev); - - return 0; -} - -struct snd_soc_codec_device soc_codec_dev_wm8903 = { - .probe = wm8903_probe, - .remove = wm8903_remove, - .suspend = wm8903_suspend, - .resume = wm8903_resume, -}; -EXPORT_SYMBOL_GPL(soc_codec_dev_wm8903); - -static int __init wm8903_modinit(void) -{ - return i2c_add_driver(&wm8903_i2c_driver); -} module_init(wm8903_modinit);
static void __exit wm8903_exit(void) { +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) i2c_del_driver(&wm8903_i2c_driver); +#endif } module_exit(wm8903_exit);
diff --git a/sound/soc/codecs/wm8903.h b/sound/soc/codecs/wm8903.h index ce384a2..6dc5748 100644 --- a/sound/soc/codecs/wm8903.h +++ b/sound/soc/codecs/wm8903.h @@ -15,8 +15,8 @@
#include <linux/i2c.h>
-extern struct snd_soc_dai wm8903_dai; -extern struct snd_soc_codec_device soc_codec_dev_wm8903; +extern struct snd_soc_dai_driver wm8903_dai; +extern struct snd_soc_codec_driver soc_codec_dev_wm8903;
extern int wm8903_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack, diff --git a/sound/soc/codecs/wm8904.c b/sound/soc/codecs/wm8904.c index 87f14f8..ea5b74a 100644 --- a/sound/soc/codecs/wm8904.c +++ b/sound/soc/codecs/wm8904.c @@ -31,9 +31,6 @@
#include "wm8904.h"
-static struct snd_soc_codec *wm8904_codec; -struct snd_soc_codec_device soc_codec_dev_wm8904; - enum wm8904_type { WM8904, WM8912, @@ -52,10 +49,11 @@ static const char *wm8904_supply_names[WM8904_NUM_SUPPLIES] = {
/* codec private data */ struct wm8904_priv { - struct snd_soc_codec codec; + u16 reg_cache[WM8904_MAX_REGISTER + 1];
enum wm8904_type devtype; + void *control_data;
struct regulator_bulk_data supplies[WM8904_NUM_SUPPLIES];
@@ -689,7 +687,7 @@ static int wm8904_put_drc_enum(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); - struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec); + struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec); struct wm8904_pdata *pdata = wm8904->pdata; int value = ucontrol->value.integer.value[0];
@@ -760,7 +758,7 @@ static int wm8904_put_retune_mobile_enum(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); - struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec); + struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec); struct wm8904_pdata *pdata = wm8904->pdata; int value = ucontrol->value.integer.value[0];
@@ -2218,7 +2216,7 @@ static struct snd_soc_dai_ops wm8904_dai_ops = { .digital_mute = wm8904_digital_mute, };
-struct snd_soc_dai wm8904_dai = { +struct snd_soc_dai_driver wm8904_dai = { .name = "WM8904", .playback = { .stream_name = "Playback", @@ -2240,21 +2238,15 @@ struct snd_soc_dai wm8904_dai = { EXPORT_SYMBOL_GPL(wm8904_dai);
#ifdef CONFIG_PM -static int wm8904_suspend(struct platform_device *pdev, pm_message_t state) +static int wm8904_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; - wm8904_set_bias_level(codec, SND_SOC_BIAS_OFF);
return 0; }
-static int wm8904_resume(struct platform_device *pdev) +static int wm8904_resume(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - wm8904_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
return 0; @@ -2264,9 +2256,9 @@ static int wm8904_resume(struct platform_device *pdev) #define wm8904_resume NULL #endif
-static void wm8904_handle_retune_mobile_pdata(struct wm8904_priv *wm8904) +static void wm8904_handle_retune_mobile_pdata(struct snd_soc_codec *codec) { - struct snd_soc_codec *codec = &wm8904->codec; + struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec); struct wm8904_pdata *pdata = wm8904->pdata; struct snd_kcontrol_new control = SOC_ENUM_EXT("EQ Mode", @@ -2315,20 +2307,20 @@ static void wm8904_handle_retune_mobile_pdata(struct wm8904_priv *wm8904) wm8904->retune_mobile_enum.max = wm8904->num_retune_mobile_texts; wm8904->retune_mobile_enum.texts = wm8904->retune_mobile_texts;
- ret = snd_soc_add_controls(&wm8904->codec, &control, 1); + ret = snd_soc_add_controls(codec, &control, 1); if (ret != 0) - dev_err(wm8904->codec.dev, + dev_err(codec->dev, "Failed to add ReTune Mobile control: %d\n", ret); }
-static void wm8904_handle_pdata(struct wm8904_priv *wm8904) +static void wm8904_handle_pdata(struct snd_soc_codec *codec) { - struct snd_soc_codec *codec = &wm8904->codec; + struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec); struct wm8904_pdata *pdata = wm8904->pdata; int ret, i;
if (!pdata) { - snd_soc_add_controls(&wm8904->codec, wm8904_eq_controls, + snd_soc_add_controls(codec, wm8904_eq_controls, ARRAY_SIZE(wm8904_eq_controls)); return; } @@ -2344,7 +2336,7 @@ static void wm8904_handle_pdata(struct wm8904_priv *wm8904) wm8904->drc_texts = kmalloc(sizeof(char *) * pdata->num_drc_cfgs, GFP_KERNEL); if (!wm8904->drc_texts) { - dev_err(wm8904->codec.dev, + dev_err(codec->dev, "Failed to allocate %d DRC config texts\n", pdata->num_drc_cfgs); return; @@ -2356,9 +2348,9 @@ static void wm8904_handle_pdata(struct wm8904_priv *wm8904) wm8904->drc_enum.max = pdata->num_drc_cfgs; wm8904->drc_enum.texts = wm8904->drc_texts;
- ret = snd_soc_add_controls(&wm8904->codec, &control, 1); + ret = snd_soc_add_controls(codec, &control, 1); if (ret != 0) - dev_err(wm8904->codec.dev, + dev_err(codec->dev, "Failed to add DRC mode control: %d\n", ret);
wm8904_set_drc(codec); @@ -2368,88 +2360,19 @@ static void wm8904_handle_pdata(struct wm8904_priv *wm8904) pdata->num_retune_mobile_cfgs);
if (pdata->num_retune_mobile_cfgs) - wm8904_handle_retune_mobile_pdata(wm8904); + wm8904_handle_retune_mobile_pdata(codec); else - snd_soc_add_controls(&wm8904->codec, wm8904_eq_controls, + snd_soc_add_controls(codec, wm8904_eq_controls, ARRAY_SIZE(wm8904_eq_controls)); }
-static int wm8904_probe(struct platform_device *pdev) -{ - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - int ret = 0; - - if (wm8904_codec == NULL) { - dev_err(&pdev->dev, "Codec device not registered\n"); - return -ENODEV; - } - - socdev->card->codec = wm8904_codec; - codec = wm8904_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; - } - - wm8904_handle_pdata(snd_soc_codec_get_drvdata(codec)); - - wm8904_add_widgets(codec); - - return ret; - -pcm_err: - return ret; -} - -static int wm8904_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_wm8904 = { - .probe = wm8904_probe, - .remove = wm8904_remove, - .suspend = wm8904_suspend, - .resume = wm8904_resume, -}; -EXPORT_SYMBOL_GPL(soc_codec_dev_wm8904); - -static int wm8904_register(struct wm8904_priv *wm8904, - enum snd_soc_control_type control) +static int wm8904_probe(struct snd_soc_codec *codec) { + struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec); struct wm8904_pdata *pdata = wm8904->pdata; - int ret; - struct snd_soc_codec *codec = &wm8904->codec; - int i; - - if (wm8904_codec) { - dev_err(codec->dev, "Another WM8904 is registered\n"); - return -EINVAL; - } + int ret, i;
- mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - snd_soc_codec_set_drvdata(codec, wm8904); - codec->name = "WM8904"; - codec->owner = THIS_MODULE; - codec->bias_level = SND_SOC_BIAS_OFF; - codec->set_bias_level = wm8904_set_bias_level; - codec->dai = &wm8904_dai; - codec->num_dai = 1; - codec->reg_cache_size = WM8904_MAX_REGISTER; - codec->reg_cache = &wm8904->reg_cache; - codec->volatile_register = wm8904_volatile_register; codec->cache_sync = 1; codec->idle_bias_off = 1;
@@ -2465,12 +2388,11 @@ static int wm8904_register(struct wm8904_priv *wm8904, return -EINVAL; }
- memcpy(codec->reg_cache, wm8904_reg, sizeof(wm8904_reg));
- ret = snd_soc_codec_set_cache_io(codec, 8, 16, control); + ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_I2C); if (ret != 0) { dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); - goto err; + return ret; }
for (i = 0; i < ARRAY_SIZE(wm8904->supplies); i++) @@ -2480,7 +2402,7 @@ static int wm8904_register(struct wm8904_priv *wm8904, wm8904->supplies); if (ret != 0) { dev_err(codec->dev, "Failed to request supplies: %d\n", ret); - goto err; + return ret; }
ret = regulator_bulk_enable(ARRAY_SIZE(wm8904->supplies), @@ -2515,8 +2437,6 @@ static int wm8904_register(struct wm8904_priv *wm8904, goto err_enable; }
- wm8904_dai.dev = codec->dev; - /* Change some default settings - latch VU and enable ZC */ wm8904->reg_cache[WM8904_ADC_DIGITAL_VOLUME_LEFT] |= WM8904_ADC_VU; wm8904->reg_cache[WM8904_ADC_DIGITAL_VOLUME_RIGHT] |= WM8904_ADC_VU; @@ -2561,20 +2481,9 @@ static int wm8904_register(struct wm8904_priv *wm8904, /* Bias level configuration will have done an extra enable */ regulator_bulk_disable(ARRAY_SIZE(wm8904->supplies), wm8904->supplies);
- wm8904_codec = codec; + wm8904_handle_pdata(codec);
- ret = snd_soc_register_codec(codec); - if (ret != 0) { - dev_err(codec->dev, "Failed to register codec: %d\n", ret); - return ret; - } - - ret = snd_soc_register_dai(&wm8904_dai); - if (ret != 0) { - dev_err(codec->dev, "Failed to register DAI: %d\n", ret); - snd_soc_unregister_codec(codec); - return ret; - } + wm8904_add_widgets(codec);
return 0;
@@ -2582,50 +2491,61 @@ err_enable: regulator_bulk_disable(ARRAY_SIZE(wm8904->supplies), wm8904->supplies); err_get: regulator_bulk_free(ARRAY_SIZE(wm8904->supplies), wm8904->supplies); -err: - kfree(wm8904); return ret; }
-static void wm8904_unregister(struct wm8904_priv *wm8904) +static int wm8904_remove(struct snd_soc_codec *codec) { - wm8904_set_bias_level(&wm8904->codec, SND_SOC_BIAS_OFF); + struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec); + + wm8904_set_bias_level(codec, SND_SOC_BIAS_OFF); regulator_bulk_free(ARRAY_SIZE(wm8904->supplies), wm8904->supplies); - snd_soc_unregister_dai(&wm8904_dai); - snd_soc_unregister_codec(&wm8904->codec); - kfree(wm8904); - wm8904_codec = NULL; + + return 0; }
+struct snd_soc_codec_driver soc_codec_dev_wm8904 = { + .name = "wm8904", + .owner = THIS_MODULE, + .probe = wm8904_probe, + .remove = wm8904_remove, + .suspend = wm8904_suspend, + .resume = wm8904_resume, + .set_bias_level = wm8904_set_bias_level, + .reg_cache_size = ARRAY_SIZE(wm8904_reg), + .reg_word_size = sizeof(u16), + .reg_cache_default = wm8904_reg, + .volatile_register = wm8904_volatile_register, +}; +EXPORT_SYMBOL_GPL(soc_codec_dev_wm8904); + #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) static __devinit int wm8904_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct wm8904_priv *wm8904; - struct snd_soc_codec *codec; + int ret;
wm8904 = kzalloc(sizeof(struct wm8904_priv), GFP_KERNEL); if (wm8904 == NULL) return -ENOMEM;
- codec = &wm8904->codec; - codec->hw_write = (hw_write_t)i2c_master_send; - wm8904->devtype = id->driver_data; - i2c_set_clientdata(i2c, wm8904); - codec->control_data = i2c; + wm8904->control_data = i2c; wm8904->pdata = i2c->dev.platform_data;
- codec->dev = &i2c->dev; - - return wm8904_register(wm8904, SND_SOC_I2C); + ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &soc_codec_dev_wm8904, &wm8904_dai, 1); + if (ret < 0) + kfree(wm8904); + return ret; }
static __devexit int wm8904_i2c_remove(struct i2c_client *client) { - struct wm8904_priv *wm8904 = i2c_get_clientdata(client); - wm8904_unregister(wm8904); + snd_soc_unregister_codec(&client->dev, client->addr); + kfree(i2c_get_clientdata(client)); return 0; }
@@ -2638,7 +2558,7 @@ MODULE_DEVICE_TABLE(i2c, wm8904_i2c_id);
static struct i2c_driver wm8904_i2c_driver = { .driver = { - .name = "WM8904", + .name = "wm8904 I2C Codec", .owner = THIS_MODULE, }, .probe = wm8904_i2c_probe, @@ -2649,15 +2569,15 @@ static struct i2c_driver wm8904_i2c_driver = {
static int __init wm8904_modinit(void) { - int ret; + int ret = 0; #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) ret = i2c_add_driver(&wm8904_i2c_driver); if (ret != 0) { - printk(KERN_ERR "Failed to register WM8904 I2C driver: %d\n", + printk(KERN_ERR "Failed to register wm8904 I2C driver: %d\n", ret); } #endif - return 0; + return ret; } module_init(wm8904_modinit);
diff --git a/sound/soc/codecs/wm8904.h b/sound/soc/codecs/wm8904.h index abe5059..3d87967 100644 --- a/sound/soc/codecs/wm8904.h +++ b/sound/soc/codecs/wm8904.h @@ -21,8 +21,8 @@ #define WM8904_FLL_LRCLK 3 #define WM8904_FLL_FREE_RUNNING 4
-extern struct snd_soc_dai wm8904_dai; -extern struct snd_soc_codec_device soc_codec_dev_wm8904; +extern struct snd_soc_dai_driver wm8904_dai; +extern struct snd_soc_codec_driver soc_codec_dev_wm8904;
/* * Register values. diff --git a/sound/soc/codecs/wm8955.c b/sound/soc/codecs/wm8955.c index fedb764..5dc61d7 100644 --- a/sound/soc/codecs/wm8955.c +++ b/sound/soc/codecs/wm8955.c @@ -30,9 +30,6 @@
#include "wm8955.h"
-static struct snd_soc_codec *wm8955_codec; -struct snd_soc_codec_device soc_codec_dev_wm8955; - #define WM8955_NUM_SUPPLIES 4 static const char *wm8955_supply_names[WM8955_NUM_SUPPLIES] = { "DCVDD", @@ -43,7 +40,9 @@ static const char *wm8955_supply_names[WM8955_NUM_SUPPLIES] = {
/* codec private data */ struct wm8955_priv { - struct snd_soc_codec codec; + enum snd_soc_control_type control_type; + void *control_data; + u16 reg_cache[WM8955_MAX_REGISTER + 1];
unsigned int mclk_rate; @@ -52,8 +51,6 @@ struct wm8955_priv { int fs;
struct regulator_bulk_data supplies[WM8955_NUM_SUPPLIES]; - - struct wm8955_pdata *pdata; };
static const u16 wm8955_reg[WM8955_MAX_REGISTER + 1] = { @@ -870,7 +867,7 @@ static struct snd_soc_dai_ops wm8955_dai_ops = { .digital_mute = wm8955_digital_mute, };
-struct snd_soc_dai wm8955_dai = { +struct snd_soc_dai_driver wm8955_dai = { .name = "WM8955", .playback = { .stream_name = "Playback", @@ -884,21 +881,15 @@ struct snd_soc_dai wm8955_dai = { EXPORT_SYMBOL_GPL(wm8955_dai);
#ifdef CONFIG_PM -static int wm8955_suspend(struct platform_device *pdev, pm_message_t state) +static int wm8955_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; - wm8955_set_bias_level(codec, SND_SOC_BIAS_OFF);
return 0; }
-static int wm8955_resume(struct platform_device *pdev) +static int wm8955_resume(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - wm8955_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
return 0; @@ -908,85 +899,17 @@ static int wm8955_resume(struct platform_device *pdev) #define wm8955_resume NULL #endif
-static int wm8955_probe(struct platform_device *pdev) -{ - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - int ret = 0; - - if (wm8955_codec == NULL) { - dev_err(&pdev->dev, "Codec device not registered\n"); - return -ENODEV; - } - - socdev->card->codec = wm8955_codec; - codec = wm8955_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; - } - - wm8955_add_widgets(codec); - - return ret; - -pcm_err: - return ret; -} - -static int wm8955_remove(struct platform_device *pdev) +static int wm8955_probe(struct snd_soc_codec *codec) { - 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_wm8955 = { - .probe = wm8955_probe, - .remove = wm8955_remove, - .suspend = wm8955_suspend, - .resume = wm8955_resume, -}; -EXPORT_SYMBOL_GPL(soc_codec_dev_wm8955); - -static int wm8955_register(struct wm8955_priv *wm8955, - enum snd_soc_control_type control) -{ - int ret; - struct snd_soc_codec *codec = &wm8955->codec; - int i; - - if (wm8955_codec) { - dev_err(codec->dev, "Another WM8955 is registered\n"); - return -EINVAL; - } - - mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - snd_soc_codec_set_drvdata(codec, wm8955); - codec->name = "WM8955"; - codec->owner = THIS_MODULE; - codec->bias_level = SND_SOC_BIAS_OFF; - codec->set_bias_level = wm8955_set_bias_level; - codec->dai = &wm8955_dai; - codec->num_dai = 1; - codec->reg_cache_size = WM8955_MAX_REGISTER; - codec->reg_cache = &wm8955->reg_cache; - - memcpy(codec->reg_cache, wm8955_reg, sizeof(wm8955_reg)); + struct wm8955_priv *wm8955 = snd_soc_codec_get_drvdata(codec); + struct wm8955_pdata *pdata = dev_get_platdata(codec->dev); + int ret, i;
- ret = snd_soc_codec_set_cache_io(codec, 7, 9, control); + codec->control_data = wm8955->control_data; + ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8955->control_type); if (ret != 0) { dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); - goto err; + return ret; }
for (i = 0; i < ARRAY_SIZE(wm8955->supplies); i++) @@ -996,7 +919,7 @@ static int wm8955_register(struct wm8955_priv *wm8955, wm8955->supplies); if (ret != 0) { dev_err(codec->dev, "Failed to request supplies: %d\n", ret); - goto err; + return ret; }
ret = regulator_bulk_enable(ARRAY_SIZE(wm8955->supplies), @@ -1012,8 +935,6 @@ static int wm8955_register(struct wm8955_priv *wm8955, goto err_enable; }
- wm8955_dai.dev = codec->dev; - /* Change some default settings - latch VU and enable ZC */ wm8955->reg_cache[WM8955_LEFT_DAC_VOLUME] |= WM8955_LDVU; wm8955->reg_cache[WM8955_RIGHT_DAC_VOLUME] |= WM8955_RDVU; @@ -1027,12 +948,12 @@ static int wm8955_register(struct wm8955_priv *wm8955, wm8955->reg_cache[WM8955_BASS_CONTROL] |= WM8955_BB;
/* Set platform data values */ - if (wm8955->pdata) { - if (wm8955->pdata->out2_speaker) + if (pdata) { + if (pdata->out2_speaker) wm8955->reg_cache[WM8955_ADDITIONAL_CONTROL_2] |= WM8955_ROUT2INV;
- if (wm8955->pdata->monoin_diff) + if (pdata->monoin_diff) wm8955->reg_cache[WM8955_MONO_OUT_MIX_1] |= WM8955_DMEN; } @@ -1042,69 +963,64 @@ static int wm8955_register(struct wm8955_priv *wm8955, /* Bias level configuration will have done an extra enable */ regulator_bulk_disable(ARRAY_SIZE(wm8955->supplies), wm8955->supplies);
- wm8955_codec = codec; - - ret = snd_soc_register_codec(codec); - if (ret != 0) { - dev_err(codec->dev, "Failed to register codec: %d\n", ret); - return ret; - } - - ret = snd_soc_register_dai(&wm8955_dai); - if (ret != 0) { - dev_err(codec->dev, "Failed to register DAI: %d\n", ret); - snd_soc_unregister_codec(codec); - return ret; - } - + wm8955_add_widgets(codec); return 0;
err_enable: regulator_bulk_disable(ARRAY_SIZE(wm8955->supplies), wm8955->supplies); err_get: regulator_bulk_free(ARRAY_SIZE(wm8955->supplies), wm8955->supplies); -err: - kfree(wm8955); return ret; }
-static void wm8955_unregister(struct wm8955_priv *wm8955) +static int wm8955_remove(struct snd_soc_codec *codec) { - wm8955_set_bias_level(&wm8955->codec, SND_SOC_BIAS_OFF); + struct wm8955_priv *wm8955 = snd_soc_codec_get_drvdata(codec); + + wm8955_set_bias_level(codec, SND_SOC_BIAS_OFF); regulator_bulk_free(ARRAY_SIZE(wm8955->supplies), wm8955->supplies); - snd_soc_unregister_dai(&wm8955_dai); - snd_soc_unregister_codec(&wm8955->codec); - kfree(wm8955); - wm8955_codec = NULL; + return 0; }
+struct snd_soc_codec_driver soc_codec_dev_wm8955 = { + .name = "wm8955", + .owner = THIS_MODULE, + .probe = wm8955_probe, + .remove = wm8955_remove, + .suspend = wm8955_suspend, + .resume = wm8955_resume, + .set_bias_level = wm8955_set_bias_level, + .reg_cache_size = ARRAY_SIZE(wm8955_reg), + .reg_word_size = sizeof(u16), + .reg_cache_default = wm8955_reg, +}; +EXPORT_SYMBOL_GPL(soc_codec_dev_wm8955); + #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) static __devinit int wm8955_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct wm8955_priv *wm8955; - struct snd_soc_codec *codec; + int ret;
wm8955 = kzalloc(sizeof(struct wm8955_priv), GFP_KERNEL); if (wm8955 == NULL) return -ENOMEM;
- codec = &wm8955->codec; - codec->hw_write = (hw_write_t)i2c_master_send; - i2c_set_clientdata(i2c, wm8955); - codec->control_data = i2c; - wm8955->pdata = i2c->dev.platform_data; - - codec->dev = &i2c->dev; + wm8955->control_data = i2c;
- return wm8955_register(wm8955, SND_SOC_I2C); + ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &soc_codec_dev_wm8955, &wm8955_dai, 1); + if (ret < 0) + kfree(wm8955); + return ret; }
static __devexit int wm8955_i2c_remove(struct i2c_client *client) { - struct wm8955_priv *wm8955 = i2c_get_clientdata(client); - wm8955_unregister(wm8955); + snd_soc_unregister_codec(&client->dev, client->addr); + kfree(i2c_get_clientdata(client)); return 0; }
@@ -1116,7 +1032,7 @@ MODULE_DEVICE_TABLE(i2c, wm8955_i2c_id);
static struct i2c_driver wm8955_i2c_driver = { .driver = { - .name = "wm8955", + .name = "WM8955 I2C Codec", .owner = THIS_MODULE, }, .probe = wm8955_i2c_probe, @@ -1127,7 +1043,7 @@ static struct i2c_driver wm8955_i2c_driver = {
static int __init wm8955_modinit(void) { - int ret; + int ret = 0; #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) ret = i2c_add_driver(&wm8955_i2c_driver); if (ret != 0) { @@ -1135,7 +1051,7 @@ static int __init wm8955_modinit(void) ret); } #endif - return 0; + return ret; } module_init(wm8955_modinit);
diff --git a/sound/soc/codecs/wm8955.h b/sound/soc/codecs/wm8955.h index ae349c8..c48c5c5 100644 --- a/sound/soc/codecs/wm8955.h +++ b/sound/soc/codecs/wm8955.h @@ -15,8 +15,8 @@
#define WM8955_CLK_MCLK 1
-extern struct snd_soc_dai wm8955_dai; -extern struct snd_soc_codec_device soc_codec_dev_wm8955; +extern struct snd_soc_dai_driver wm8955_dai; +extern struct snd_soc_codec_driver soc_codec_dev_wm8955;
/* * Register values.
Move Wolfson CODECs to multi-component model
This patch changes the probe() and remove() of the CODEC drivers as follows:-
o Make CODEC driver a platform device (non MFD codecs only) o Moved all struct snd_soc_codec list, mutex, etc initialiasation to core. o Removed all static codec pointers (drivers now support > 1 codec dev) o snd_soc_register_pcms() now done by core. o snd_soc_register_dai() folded into snd_soc_register_codec(). o codec cache can now be malloc()ed by core.
Other required changes due to multi-component model :-
o wm8960: codec device no longer has set_bias(), so func moved to private data.
Signed-off-by: Liam Girdwood lrg@slimlogic.co.uk --- sound/soc/codecs/wm8940.c | 198 ++++++++++++-------------------------- sound/soc/codecs/wm8940.h | 4 +- sound/soc/codecs/wm8960.c | 206 +++++++++++++-------------------------- sound/soc/codecs/wm8960.h | 4 +- sound/soc/codecs/wm8961.c | 237 +++++++++++++++------------------------------ sound/soc/codecs/wm8961.h | 4 +- 6 files changed, 213 insertions(+), 440 deletions(-)
diff --git a/sound/soc/codecs/wm8940.c b/sound/soc/codecs/wm8940.c index e3c4bbf..1245cf6 100644 --- a/sound/soc/codecs/wm8940.c +++ b/sound/soc/codecs/wm8940.c @@ -44,7 +44,8 @@ struct wm8940_priv { unsigned int sysclk; u16 reg_cache[WM8940_CACHEREGNUM]; - struct snd_soc_codec codec; + enum snd_soc_control_type control_type; + void *control_data; };
static u16 wm8940_reg_defaults[] = { @@ -365,8 +366,7 @@ static int wm8940_i2s_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; u16 iface = snd_soc_read(codec, WM8940_IFACE) & 0xFD9F; u16 addcntrl = snd_soc_read(codec, WM8940_ADDCNTRL) & 0xFFF1; u16 companding = snd_soc_read(codec, @@ -636,7 +636,7 @@ static struct snd_soc_dai_ops wm8940_dai_ops = { .set_pll = wm8940_set_dai_pll, };
-struct snd_soc_dai wm8940_dai = { +struct snd_soc_dai_driver wm8940_dai = { .name = "WM8940", .playback = { .stream_name = "Playback", @@ -657,18 +657,13 @@ struct snd_soc_dai wm8940_dai = { }; EXPORT_SYMBOL_GPL(wm8940_dai);
-static int wm8940_suspend(struct platform_device *pdev, pm_message_t state) +static int wm8940_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; - return wm8940_set_bias_level(codec, SND_SOC_BIAS_OFF); }
-static int wm8940_resume(struct platform_device *pdev) +static int wm8940_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; int ret; u8 data[3]; @@ -697,108 +692,26 @@ error_ret: return ret; }
-static struct snd_soc_codec *wm8940_codec; - -static int wm8940_probe(struct platform_device *pdev) +static int wm8940_probe(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - - int ret = 0; - - if (wm8940_codec == NULL) { - dev_err(&pdev->dev, "Codec device not registered\n"); - return -ENODEV; - } - - socdev->card->codec = wm8940_codec; - codec = wm8940_codec; - - mutex_init(&codec->mutex); - /* 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; - } - - ret = snd_soc_add_controls(codec, wm8940_snd_controls, - ARRAY_SIZE(wm8940_snd_controls)); - if (ret) - goto error_free_pcms; - ret = wm8940_add_widgets(codec); - if (ret) - goto error_free_pcms; - - return ret; - -error_free_pcms: - snd_soc_free_pcms(socdev); - snd_soc_dapm_free(socdev); -pcm_err: - return ret; -} - -static int wm8940_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_wm8940 = { - .probe = wm8940_probe, - .remove = wm8940_remove, - .suspend = wm8940_suspend, - .resume = wm8940_resume, -}; -EXPORT_SYMBOL_GPL(soc_codec_dev_wm8940); - -static int wm8940_register(struct wm8940_priv *wm8940, - enum snd_soc_control_type control) -{ - struct wm8940_setup_data *pdata = wm8940->codec.dev->platform_data; - struct snd_soc_codec *codec = &wm8940->codec; + struct wm8940_priv *wm8940 = snd_soc_codec_get_drvdata(codec); + struct wm8940_setup_data *pdata = codec->dev->platform_data; int ret; u16 reg; - if (wm8940_codec) { - dev_err(codec->dev, "Another WM8940 is registered\n"); - return -EINVAL; - } - - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - snd_soc_codec_set_drvdata(codec, wm8940); - codec->name = "WM8940"; - codec->owner = THIS_MODULE; - codec->bias_level = SND_SOC_BIAS_OFF; - codec->set_bias_level = wm8940_set_bias_level; - codec->dai = &wm8940_dai; - codec->num_dai = 1; - codec->reg_cache_size = ARRAY_SIZE(wm8940_reg_defaults); - codec->reg_cache = &wm8940->reg_cache;
- ret = snd_soc_codec_set_cache_io(codec, 8, 16, control); + codec->control_data = wm8940->control_data; + ret = snd_soc_codec_set_cache_io(codec, 8, 16, wm8940->control_type); if (ret < 0) { dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); return ret; }
- memcpy(codec->reg_cache, wm8940_reg_defaults, - sizeof(wm8940_reg_defaults)); - ret = wm8940_reset(codec); if (ret < 0) { dev_err(codec->dev, "Failed to issue reset\n"); return ret; }
- wm8940_dai.dev = codec->dev; - wm8940_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
ret = snd_soc_write(codec, WM8940_POWER1, 0x180); @@ -814,59 +727,63 @@ static int wm8940_register(struct wm8940_priv *wm8940, return ret; }
- - wm8940_codec = codec; - - ret = snd_soc_register_codec(codec); - if (ret) { - dev_err(codec->dev, "Failed to register codec: %d\n", ret); + ret = snd_soc_add_controls(codec, wm8940_snd_controls, + ARRAY_SIZE(wm8940_snd_controls)); + if (ret) return ret; - } - - ret = snd_soc_register_dai(&wm8940_dai); - if (ret) { - dev_err(codec->dev, "Failed to register DAI: %d\n", ret); - snd_soc_unregister_codec(codec); + ret = wm8940_add_widgets(codec); + if (ret) return ret; - }
- return 0; + return ret; +; }
-static void wm8940_unregister(struct wm8940_priv *wm8940) +static int wm8940_remove(struct snd_soc_codec *codec) { - wm8940_set_bias_level(&wm8940->codec, SND_SOC_BIAS_OFF); - snd_soc_unregister_dai(&wm8940_dai); - snd_soc_unregister_codec(&wm8940->codec); - kfree(wm8940); - wm8940_codec = NULL; + wm8940_set_bias_level(codec, SND_SOC_BIAS_OFF); + return 0; }
-static int wm8940_i2c_probe(struct i2c_client *i2c, - const struct i2c_device_id *id) +struct snd_soc_codec_driver soc_codec_dev_wm8940 = { + .name = "wm8940", + .owner = THIS_MODULE, + .probe = wm8940_probe, + .remove = wm8940_remove, + .suspend = wm8940_suspend, + .resume = wm8940_resume, + .set_bias_level = wm8940_set_bias_level, + .reg_cache_size = sizeof(wm8940_reg_defaults), + .reg_word_size = sizeof(u16), + .reg_cache_default = wm8940_reg_defaults, +}; +EXPORT_SYMBOL_GPL(soc_codec_dev_wm8940); + +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) +static __devinit int wm8940_i2c_probe(struct i2c_client *i2c, + const struct i2c_device_id *id) { struct wm8940_priv *wm8940; - struct snd_soc_codec *codec; + int ret;
- wm8940 = kzalloc(sizeof *wm8940, GFP_KERNEL); + wm8940 = kzalloc(sizeof(struct wm8940_priv), GFP_KERNEL); if (wm8940 == NULL) return -ENOMEM;
- codec = &wm8940->codec; - codec->hw_write = (hw_write_t)i2c_master_send; i2c_set_clientdata(i2c, wm8940); - codec->control_data = i2c; - codec->dev = &i2c->dev; + wm8940->control_data = i2c;
- return wm8940_register(wm8940, SND_SOC_I2C); + ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &soc_codec_dev_wm8940, &wm8940_dai, 1); + if (ret < 0) + kfree(wm8940); + return ret; }
-static int __devexit wm8940_i2c_remove(struct i2c_client *client) +static __devexit int wm8940_i2c_remove(struct i2c_client *client) { - struct wm8940_priv *wm8940 = i2c_get_clientdata(client); - - wm8940_unregister(wm8940); - + snd_soc_unregister_codec(&client->dev, client->addr); + kfree(i2c_get_clientdata(client)); return 0; }
@@ -881,26 +798,31 @@ static struct i2c_driver wm8940_i2c_driver = { .name = "WM8940 I2C Codec", .owner = THIS_MODULE, }, - .probe = wm8940_i2c_probe, - .remove = __devexit_p(wm8940_i2c_remove), + .probe = wm8940_i2c_probe, + .remove = __devexit_p(wm8940_i2c_remove), .id_table = wm8940_i2c_id, }; +#endif
static int __init wm8940_modinit(void) { - int ret; - + int ret = 0; +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) ret = i2c_add_driver(&wm8940_i2c_driver); - if (ret) - printk(KERN_ERR "Failed to register WM8940 I2C driver: %d\n", + if (ret != 0) { + printk(KERN_ERR "Failed to register wm8940 I2C driver: %d\n", ret); + } +#endif return ret; } module_init(wm8940_modinit);
static void __exit wm8940_exit(void) { +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) i2c_del_driver(&wm8940_i2c_driver); +#endif } module_exit(wm8940_exit);
diff --git a/sound/soc/codecs/wm8940.h b/sound/soc/codecs/wm8940.h index 8410eed..7c76b87 100644 --- a/sound/soc/codecs/wm8940.h +++ b/sound/soc/codecs/wm8940.h @@ -15,8 +15,8 @@ struct wm8940_setup_data { #define WM8940_VROI_30K 1 unsigned int vroi:1; }; -extern struct snd_soc_dai wm8940_dai; -extern struct snd_soc_codec_device soc_codec_dev_wm8940; +extern struct snd_soc_dai_driver wm8940_dai; +extern struct snd_soc_codec_driver soc_codec_dev_wm8940;
/* WM8940 register space */ #define WM8940_SOFTRESET 0x00 diff --git a/sound/soc/codecs/wm8960.c b/sound/soc/codecs/wm8960.c index 7233cc6..9c88f6a 100644 --- a/sound/soc/codecs/wm8960.c +++ b/sound/soc/codecs/wm8960.c @@ -29,8 +29,6 @@
#define AUDIO_NAME "wm8960"
-struct snd_soc_codec_device soc_codec_dev_wm8960; - /* R25 - Power 1 */ #define WM8960_VMID_MASK 0x180 #define WM8960_VREF 0x40 @@ -75,7 +73,10 @@ static const u16 wm8960_reg[WM8960_CACHEREGNUM] = {
struct wm8960_priv { u16 reg_cache[WM8960_CACHEREGNUM]; - struct snd_soc_codec codec; + enum snd_soc_control_type control_type; + void *control_data; + int (*set_bias_level)(struct snd_soc_codec *, + enum snd_soc_bias_level level); struct snd_soc_dapm_widget *lout1; struct snd_soc_dapm_widget *rout1; struct snd_soc_dapm_widget *out3; @@ -438,8 +439,7 @@ static int wm8960_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; u16 iface = snd_soc_read(codec, WM8960_IFACE1) & 0xfff3;
/* bit size */ @@ -766,6 +766,14 @@ static int wm8960_set_dai_clkdiv(struct snd_soc_dai *codec_dai, return 0; }
+static int wm8960_set_bias_level(struct snd_soc_codec *codec, + enum snd_soc_bias_level level) +{ + struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); + + return wm8960->set_bias_level(codec, level); +} + #define WM8960_RATES SNDRV_PCM_RATE_8000_48000
#define WM8960_FORMATS \ @@ -780,7 +788,7 @@ static struct snd_soc_dai_ops wm8960_dai_ops = { .set_pll = wm8960_set_dai_pll, };
-struct snd_soc_dai wm8960_dai = { +struct snd_soc_dai_driver wm8960_dai = { .name = "WM8960", .playback = { .stream_name = "Playback", @@ -799,19 +807,17 @@ struct snd_soc_dai wm8960_dai = { }; EXPORT_SYMBOL_GPL(wm8960_dai);
-static int wm8960_suspend(struct platform_device *pdev, pm_message_t state) +static int wm8960_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; + struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
- codec->set_bias_level(codec, SND_SOC_BIAS_OFF); + wm8960->set_bias_level(codec, SND_SOC_BIAS_OFF); return 0; }
-static int wm8960_resume(struct platform_device *pdev) +static int wm8960_resume(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; + struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); int i; u8 data[2]; u16 *cache = codec->reg_cache; @@ -823,78 +829,19 @@ static int wm8960_resume(struct platform_device *pdev) codec->hw_write(codec->control_data, data, 2); }
- codec->set_bias_level(codec, SND_SOC_BIAS_STANDBY); - + wm8960->set_bias_level(codec, SND_SOC_BIAS_STANDBY); return 0; }
-static struct snd_soc_codec *wm8960_codec; - -static int wm8960_probe(struct platform_device *pdev) +static int wm8960_probe(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - int ret = 0; - - if (wm8960_codec == NULL) { - dev_err(&pdev->dev, "Codec device not registered\n"); - return -ENODEV; - } - - socdev->card->codec = wm8960_codec; - codec = wm8960_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, wm8960_snd_controls, - ARRAY_SIZE(wm8960_snd_controls)); - wm8960_add_widgets(codec); - - return ret; - -pcm_err: - return ret; -} - -/* power down chip */ -static int wm8960_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_wm8960 = { - .probe = wm8960_probe, - .remove = wm8960_remove, - .suspend = wm8960_suspend, - .resume = wm8960_resume, -}; -EXPORT_SYMBOL_GPL(soc_codec_dev_wm8960); - -static int wm8960_register(struct wm8960_priv *wm8960, - enum snd_soc_control_type control) -{ - struct wm8960_data *pdata = wm8960->codec.dev->platform_data; - struct snd_soc_codec *codec = &wm8960->codec; + struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); + struct wm8960_data *pdata = dev_get_platdata(codec->dev); int ret; u16 reg;
- if (wm8960_codec) { - dev_err(codec->dev, "Another WM8960 is registered\n"); - ret = -EINVAL; - goto err; - } - - codec->set_bias_level = wm8960_set_bias_level_out3; + wm8960->set_bias_level = wm8960_set_bias_level_out3; + codec->control_data = wm8960->control_data;
if (!pdata) { dev_warn(codec->dev, "No platform data supplied\n"); @@ -905,39 +852,22 @@ static int wm8960_register(struct wm8960_priv *wm8960, }
if (pdata->capless) - codec->set_bias_level = wm8960_set_bias_level_capless; + wm8960->set_bias_level = wm8960_set_bias_level_capless; }
- mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - snd_soc_codec_set_drvdata(codec, wm8960); - codec->name = "WM8960"; - codec->owner = THIS_MODULE; - codec->bias_level = SND_SOC_BIAS_OFF; - codec->dai = &wm8960_dai; - codec->num_dai = 1; - codec->reg_cache_size = WM8960_CACHEREGNUM; - codec->reg_cache = &wm8960->reg_cache; - - memcpy(codec->reg_cache, wm8960_reg, sizeof(wm8960_reg)); - - ret = snd_soc_codec_set_cache_io(codec, 7, 9, control); + ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8960->control_type); if (ret < 0) { dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); - goto err; + return ret; }
ret = wm8960_reset(codec); if (ret < 0) { dev_err(codec->dev, "Failed to issue reset\n"); - goto err; + return ret; }
- wm8960_dai.dev = codec->dev; - - codec->set_bias_level(codec, SND_SOC_BIAS_STANDBY); + wm8960->set_bias_level(codec, SND_SOC_BIAS_STANDBY);
/* Latch the update bits */ reg = snd_soc_read(codec, WM8960_LINVOL); @@ -961,62 +891,61 @@ static int wm8960_register(struct wm8960_priv *wm8960, reg = snd_soc_read(codec, WM8960_ROUT2); snd_soc_write(codec, WM8960_ROUT2, reg | 0x100);
- wm8960_codec = codec; - - ret = snd_soc_register_codec(codec); - if (ret != 0) { - dev_err(codec->dev, "Failed to register codec: %d\n", ret); - goto err; - } - - ret = snd_soc_register_dai(&wm8960_dai); - if (ret != 0) { - dev_err(codec->dev, "Failed to register DAI: %d\n", ret); - goto err_codec; - } + snd_soc_add_controls(codec, wm8960_snd_controls, + ARRAY_SIZE(wm8960_snd_controls)); + wm8960_add_widgets(codec);
return 0; - -err_codec: - snd_soc_unregister_codec(codec); -err: - kfree(wm8960); - return ret; }
-static void wm8960_unregister(struct wm8960_priv *wm8960) +/* power down chip */ +static int wm8960_remove(struct snd_soc_codec *codec) { - wm8960->codec.set_bias_level(&wm8960->codec, SND_SOC_BIAS_OFF); - snd_soc_unregister_dai(&wm8960_dai); - snd_soc_unregister_codec(&wm8960->codec); - kfree(wm8960); - wm8960_codec = NULL; + struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); + + wm8960->set_bias_level(codec, SND_SOC_BIAS_OFF); + return 0; }
+struct snd_soc_codec_driver soc_codec_dev_wm8960 = { + .name = "wm8960", + .owner = THIS_MODULE, + .probe = wm8960_probe, + .remove = wm8960_remove, + .suspend = wm8960_suspend, + .resume = wm8960_resume, + .set_bias_level = wm8960_set_bias_level, + .reg_cache_size = ARRAY_SIZE(wm8960_reg), + .reg_word_size = sizeof(u16), + .reg_cache_default = wm8960_reg, +}; +EXPORT_SYMBOL_GPL(soc_codec_dev_wm8960); + +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) static __devinit int wm8960_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct wm8960_priv *wm8960; - struct snd_soc_codec *codec; + int ret;
wm8960 = kzalloc(sizeof(struct wm8960_priv), GFP_KERNEL); if (wm8960 == NULL) return -ENOMEM;
- codec = &wm8960->codec; - i2c_set_clientdata(i2c, wm8960); - codec->control_data = i2c; + wm8960->control_data = i2c;
- codec->dev = &i2c->dev; - - return wm8960_register(wm8960, SND_SOC_I2C); + ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &soc_codec_dev_wm8960, &wm8960_dai, 1); + if (ret < 0) + kfree(wm8960); + return ret; }
static __devexit int wm8960_i2c_remove(struct i2c_client *client) { - struct wm8960_priv *wm8960 = i2c_get_clientdata(client); - wm8960_unregister(wm8960); + snd_soc_unregister_codec(&client->dev, client->addr); + kfree(i2c_get_clientdata(client)); return 0; }
@@ -1035,24 +964,27 @@ static struct i2c_driver wm8960_i2c_driver = { .remove = __devexit_p(wm8960_i2c_remove), .id_table = wm8960_i2c_id, }; +#endif
static int __init wm8960_modinit(void) { - int ret; - + int ret = 0; +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) ret = i2c_add_driver(&wm8960_i2c_driver); if (ret != 0) { printk(KERN_ERR "Failed to register WM8960 I2C driver: %d\n", ret); } - +#endif return ret; } module_init(wm8960_modinit);
static void __exit wm8960_exit(void) { +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) i2c_del_driver(&wm8960_i2c_driver); +#endif } module_exit(wm8960_exit);
diff --git a/sound/soc/codecs/wm8960.h b/sound/soc/codecs/wm8960.h index a5ef654..ab8899c 100644 --- a/sound/soc/codecs/wm8960.h +++ b/sound/soc/codecs/wm8960.h @@ -110,7 +110,7 @@ #define WM8960_OPCLK_DIV_5_5 (4 << 0) #define WM8960_OPCLK_DIV_6 (5 << 0)
-extern struct snd_soc_dai wm8960_dai; -extern struct snd_soc_codec_device soc_codec_dev_wm8960; +extern struct snd_soc_dai_driver wm8960_dai; +extern struct snd_soc_codec_driver soc_codec_dev_wm8960;
#endif diff --git a/sound/soc/codecs/wm8961.c b/sound/soc/codecs/wm8961.c index 5b9a756..ad112c9 100644 --- a/sound/soc/codecs/wm8961.c +++ b/sound/soc/codecs/wm8961.c @@ -288,7 +288,8 @@ static u16 wm8961_reg_defaults[] = { };
struct wm8961_priv { - struct snd_soc_codec codec; + enum snd_soc_control_type control_type; + void *control_data; int sysclk; u16 reg_cache[WM8961_MAX_REGISTER]; }; @@ -940,7 +941,7 @@ static struct snd_soc_dai_ops wm8961_dai_ops = { .set_clkdiv = wm8961_set_clkdiv, };
-struct snd_soc_dai wm8961_dai = { +struct snd_soc_dai_driver wm8961_dai = { .name = "WM8961", .playback = { .stream_name = "HiFi Playback", @@ -958,138 +959,24 @@ struct snd_soc_dai wm8961_dai = { }; EXPORT_SYMBOL_GPL(wm8961_dai);
- -static struct snd_soc_codec *wm8961_codec; - -static int wm8961_probe(struct platform_device *pdev) +static int wm8961_probe(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; + struct wm8961_priv *wm8961 = snd_soc_codec_get_drvdata(codec); int ret = 0; - - if (wm8961_codec == NULL) { - dev_err(&pdev->dev, "Codec device not registered\n"); - return -ENODEV; - } - - socdev->card->codec = wm8961_codec; - codec = wm8961_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, wm8961_snd_controls, - ARRAY_SIZE(wm8961_snd_controls)); - snd_soc_dapm_new_controls(codec, wm8961_dapm_widgets, - ARRAY_SIZE(wm8961_dapm_widgets)); - snd_soc_dapm_add_routes(codec, audio_paths, ARRAY_SIZE(audio_paths)); - - return ret; - -pcm_err: - return ret; -} - -static int wm8961_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; -} - -#ifdef CONFIG_PM -static int wm8961_suspend(struct platform_device *pdev, pm_message_t state) -{ - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - - wm8961_set_bias_level(codec, SND_SOC_BIAS_OFF); - - return 0; -} - -static int wm8961_resume(struct platform_device *pdev) -{ - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - u16 *reg_cache = codec->reg_cache; - int i; - - for (i = 0; i < codec->reg_cache_size; i++) { - if (reg_cache[i] == wm8961_reg_defaults[i]) - continue; - - if (i == WM8961_SOFTWARE_RESET) - continue; - - snd_soc_write(codec, i, reg_cache[i]); - } - - wm8961_set_bias_level(codec, SND_SOC_BIAS_STANDBY); - - return 0; -} -#else -#define wm8961_suspend NULL -#define wm8961_resume NULL -#endif - -struct snd_soc_codec_device soc_codec_dev_wm8961 = { - .probe = wm8961_probe, - .remove = wm8961_remove, - .suspend = wm8961_suspend, - .resume = wm8961_resume, -}; -EXPORT_SYMBOL_GPL(soc_codec_dev_wm8961); - -static int wm8961_register(struct wm8961_priv *wm8961) -{ - struct snd_soc_codec *codec = &wm8961->codec; - int ret; u16 reg;
- if (wm8961_codec) { - dev_err(codec->dev, "Another WM8961 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, wm8961); - codec->name = "WM8961"; - codec->owner = THIS_MODULE; - codec->dai = &wm8961_dai; - codec->num_dai = 1; - codec->reg_cache_size = ARRAY_SIZE(wm8961->reg_cache); - codec->reg_cache = &wm8961->reg_cache; - codec->bias_level = SND_SOC_BIAS_OFF; - codec->set_bias_level = wm8961_set_bias_level; - codec->volatile_register = wm8961_volatile_register; - - memcpy(codec->reg_cache, wm8961_reg_defaults, - sizeof(wm8961_reg_defaults)); - + codec->control_data = wm8961->control_data; ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_I2C); if (ret != 0) { dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); - goto err; + return ret; }
reg = snd_soc_read(codec, WM8961_SOFTWARE_RESET); if (reg != 0x1801) { dev_err(codec->dev, "Device is not a WM8961: ID=0x%x\n", reg); ret = -EINVAL; - goto err; + return ret; }
/* This isn't volatile - readback doesn't correspond to write */ @@ -1140,63 +1027,93 @@ static int wm8961_register(struct wm8961_priv *wm8961)
wm8961_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
- wm8961_dai.dev = codec->dev; + snd_soc_add_controls(codec, wm8961_snd_controls, + ARRAY_SIZE(wm8961_snd_controls)); + snd_soc_dapm_new_controls(codec, wm8961_dapm_widgets, + ARRAY_SIZE(wm8961_dapm_widgets)); + snd_soc_dapm_add_routes(codec, audio_paths, ARRAY_SIZE(audio_paths));
- wm8961_codec = codec; + return 0; +}
- ret = snd_soc_register_codec(codec); - if (ret != 0) { - dev_err(codec->dev, "Failed to register codec: %d\n", ret); - return ret; - } +static int wm8961_remove(struct snd_soc_codec *codec) +{ + wm8961_set_bias_level(codec, SND_SOC_BIAS_OFF); + return 0; +}
- ret = snd_soc_register_dai(&wm8961_dai); - if (ret != 0) { - dev_err(codec->dev, "Failed to register DAI: %d\n", ret); - snd_soc_unregister_codec(codec); - return ret; - } +#ifdef CONFIG_PM +static int wm8961_suspend(struct snd_soc_codec *codec, pm_message_t state) +{ + wm8961_set_bias_level(codec, SND_SOC_BIAS_OFF);
return 0; - -err: - kfree(wm8961); - return ret; }
-static void wm8961_unregister(struct wm8961_priv *wm8961) +static int wm8961_resume(struct snd_soc_codec *codec) { - wm8961_set_bias_level(&wm8961->codec, SND_SOC_BIAS_OFF); - snd_soc_unregister_dai(&wm8961_dai); - snd_soc_unregister_codec(&wm8961->codec); - kfree(wm8961); - wm8961_codec = NULL; + u16 *reg_cache = codec->reg_cache; + int i; + + for (i = 0; i < codec->driver->reg_cache_size; i++) { + if (reg_cache[i] == wm8961_reg_defaults[i]) + continue; + + if (i == WM8961_SOFTWARE_RESET) + continue; + + snd_soc_write(codec, i, reg_cache[i]); + } + + wm8961_set_bias_level(codec, SND_SOC_BIAS_STANDBY); + + return 0; } +#else +#define wm8961_suspend NULL +#define wm8961_resume NULL +#endif
+struct snd_soc_codec_driver soc_codec_dev_wm8961 = { + .name = "wm8961", + .owner = THIS_MODULE, + .probe = wm8961_probe, + .remove = wm8961_remove, + .suspend = wm8961_suspend, + .resume = wm8961_resume, + .set_bias_level = wm8961_set_bias_level, + .reg_cache_size = sizeof(wm8961_reg_defaults), + .reg_word_size = sizeof(u16), + .reg_cache_default = wm8961_reg_defaults, + .volatile_register = wm8961_volatile_register, +}; +EXPORT_SYMBOL_GPL(soc_codec_dev_wm8961); + +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) static __devinit int wm8961_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct wm8961_priv *wm8961; - struct snd_soc_codec *codec; + int ret;
wm8961 = kzalloc(sizeof(struct wm8961_priv), GFP_KERNEL); if (wm8961 == NULL) return -ENOMEM;
- codec = &wm8961->codec; - i2c_set_clientdata(i2c, wm8961); - codec->control_data = i2c; + wm8961->control_data = i2c;
- codec->dev = &i2c->dev; - - return wm8961_register(wm8961); + ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &soc_codec_dev_wm8961, &wm8961_dai, 1); + if (ret < 0) + kfree(wm8961); + return ret; }
static __devexit int wm8961_i2c_remove(struct i2c_client *client) { - struct wm8961_priv *wm8961 = i2c_get_clientdata(client); - wm8961_unregister(wm8961); + snd_soc_unregister_codec(&client->dev, client->addr); + kfree(i2c_get_clientdata(client)); return 0; }
@@ -1208,35 +1125,37 @@ MODULE_DEVICE_TABLE(i2c, wm8961_i2c_id);
static struct i2c_driver wm8961_i2c_driver = { .driver = { - .name = "wm8961", + .name = "wm8961 I2C Codec", .owner = THIS_MODULE, }, .probe = wm8961_i2c_probe, .remove = __devexit_p(wm8961_i2c_remove), .id_table = wm8961_i2c_id, }; +#endif
static int __init wm8961_modinit(void) { - int ret; - + int ret = 0; +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) ret = i2c_add_driver(&wm8961_i2c_driver); if (ret != 0) { - printk(KERN_ERR "Failed to register WM8961 I2C driver: %d\n", + printk(KERN_ERR "Failed to register wm8961 I2C driver: %d\n", ret); } - +#endif return ret; } module_init(wm8961_modinit);
static void __exit wm8961_exit(void) { +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) i2c_del_driver(&wm8961_i2c_driver); +#endif } module_exit(wm8961_exit);
- MODULE_DESCRIPTION("ASoC WM8961 driver"); MODULE_AUTHOR("Mark Brown broonie@opensource.wolfsonmicro.com"); MODULE_LICENSE("GPL"); diff --git a/sound/soc/codecs/wm8961.h b/sound/soc/codecs/wm8961.h index 5513bfd..21443e4 100644 --- a/sound/soc/codecs/wm8961.h +++ b/sound/soc/codecs/wm8961.h @@ -11,8 +11,8 @@
#include <sound/soc.h>
-extern struct snd_soc_codec_device soc_codec_dev_wm8961; -extern struct snd_soc_dai wm8961_dai; +extern struct snd_soc_codec_driver soc_codec_dev_wm8961; +extern struct snd_soc_dai_driver wm8961_dai;
#define WM8961_BCLK 1 #define WM8961_LRCLK 2
Move Wolfson CODECs to multi-component model.
This patch changes the probe() and remove() of the CODEC drivers as follows:-
o Make CODEC driver a platform device (non MFD codecs only) o Moved all struct snd_soc_codec list, mutex, etc initialiasation to core. o Removed all static codec pointers (drivers now support > 1 codec dev) o snd_soc_register_pcms() now done by core. o snd_soc_register_dai() folded into snd_soc_register_codec(). o codec cache can now be malloc()ed by core.
Other required changes due to multi-component model :-
o wm8993: set_fll() needs to be accessed from both codec and dai device context, so wrapper added to acces from dai context.
Signed-off-by: Liam Girdwood lrg@slimlogic.co.uk --- sound/soc/codecs/wm8971.c | 248 ++++++++++-------------------------- sound/soc/codecs/wm8971.h | 9 +- sound/soc/codecs/wm8974.c | 168 +++++++------------------ sound/soc/codecs/wm8974.h | 4 +- sound/soc/codecs/wm8990.c | 226 ++++++++------------------------- sound/soc/codecs/wm8990.h | 9 +- sound/soc/codecs/wm8993.c | 305 ++++++++++++++++++--------------------------- sound/soc/codecs/wm8993.h | 4 +- 8 files changed, 305 insertions(+), 668 deletions(-)
diff --git a/sound/soc/codecs/wm8971.c b/sound/soc/codecs/wm8971.c index a99620f..31f4b0e 100644 --- a/sound/soc/codecs/wm8971.c +++ b/sound/soc/codecs/wm8971.c @@ -38,6 +38,8 @@ static struct workqueue_struct *wm8971_workq = NULL;
/* codec private data */ struct wm8971_priv { + enum snd_soc_control_type control_type; + void *control_data; unsigned int sysclk; };
@@ -492,8 +494,7 @@ static int wm8971_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 wm8971_priv *wm8971 = snd_soc_codec_get_drvdata(codec); u16 iface = snd_soc_read(codec, WM8971_IFACE) & 0x1f3; u16 srate = snd_soc_read(codec, WM8971_SRATE) & 0x1c0; @@ -573,7 +574,7 @@ static struct snd_soc_dai_ops wm8971_dai_ops = { .set_sysclk = wm8971_set_dai_sysclk, };
-struct snd_soc_dai wm8971_dai = { +struct snd_soc_dai_driver wm8971_dai = { .name = "WM8971", .playback = { .stream_name = "Playback", @@ -598,19 +599,14 @@ static void wm8971_work(struct work_struct *work) wm8971_set_bias_level(codec, codec->bias_level); }
-static int wm8971_suspend(struct platform_device *pdev, pm_message_t state) +static int wm8971_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; - wm8971_set_bias_level(codec, SND_SOC_BIAS_OFF); return 0; }
-static int wm8971_resume(struct platform_device *pdev) +static int wm8971_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; @@ -639,37 +635,27 @@ static int wm8971_resume(struct platform_device *pdev) return 0; }
-static int wm8971_init(struct snd_soc_device *socdev, - enum snd_soc_control_type control) +static int wm8971_probe(struct snd_soc_codec *codec) { - struct snd_soc_codec *codec = socdev->card->codec; - int reg, ret = 0; - - codec->name = "WM8971"; - codec->owner = THIS_MODULE; - codec->set_bias_level = wm8971_set_bias_level; - codec->dai = &wm8971_dai; - codec->reg_cache_size = ARRAY_SIZE(wm8971_reg); - codec->num_dai = 1; - codec->reg_cache = kmemdup(wm8971_reg, sizeof(wm8971_reg), GFP_KERNEL); - - if (codec->reg_cache == NULL) - return -ENOMEM; + struct wm8971_priv *wm8971 = snd_soc_codec_get_drvdata(codec); + int ret = 0; + u16 reg; + + pr_info("WM8971 Audio Codec %s", WM8971_VERSION);
- ret = snd_soc_codec_set_cache_io(codec, 7, 9, control); + codec->control_data = wm8971->control_data; + ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8971->control_type); if (ret < 0) { printk(KERN_ERR "wm8971: failed to set cache I/O: %d\n", ret); - goto err; + return ret; }
- wm8971_reset(codec); + INIT_DELAYED_WORK(&codec->delayed_work, wm8971_work); + wm8971_workq = create_workqueue("wm8971"); + if (wm8971_workq == NULL) + return -ENOMEM;
- /* register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret < 0) { - printk(KERN_ERR "wm8971: failed to create pcms\n"); - goto err; - } + wm8971_reset(codec);
/* charge output caps - set vmid to 5k for quick power up */ reg = snd_soc_read(codec, WM8971_PWR1) & 0xfe3e; @@ -704,40 +690,58 @@ static int wm8971_init(struct snd_soc_device *socdev, wm8971_add_widgets(codec);
return ret; - -err: - kfree(codec->reg_cache); - return ret; }
-/* If the i2c layer weren't so broken, we could pass this kind of data - around */ -static struct snd_soc_device *wm8971_socdev;
-#if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) +/* power down chip */ +static int wm8971_remove(struct snd_soc_codec *codec) +{ + wm8971_set_bias_level(codec, SND_SOC_BIAS_OFF); + + if (wm8971_workq) + destroy_workqueue(wm8971_workq); + return 0; +} + +struct snd_soc_codec_driver soc_codec_dev_wm8971 = { + .name = "wm8971", + .owner = THIS_MODULE, + .probe = wm8971_probe, + .remove = wm8971_remove, + .suspend = wm8971_suspend, + .resume = wm8971_resume, + .set_bias_level = wm8971_set_bias_level, + .reg_cache_size = ARRAY_SIZE(wm8971_reg), + .reg_word_size = sizeof(u16), + .reg_cache_default = wm8971_reg, +}; +EXPORT_SYMBOL_GPL(soc_codec_dev_wm8971);
-static int wm8971_i2c_probe(struct i2c_client *i2c, - const struct i2c_device_id *id) +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) +static __devinit int wm8971_i2c_probe(struct i2c_client *i2c, + const struct i2c_device_id *id) { - struct snd_soc_device *socdev = wm8971_socdev; - struct snd_soc_codec *codec = socdev->card->codec; + struct wm8971_priv *wm8971; int ret;
- i2c_set_clientdata(i2c, codec); + wm8971 = kzalloc(sizeof(struct wm8971_priv), GFP_KERNEL); + if (wm8971 == NULL) + return -ENOMEM;
- codec->control_data = i2c; + i2c_set_clientdata(i2c, wm8971); + wm8971->control_data = i2c;
- ret = wm8971_init(socdev, SND_SOC_I2C); + ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &soc_codec_dev_wm8971, &wm8971_dai, 1); if (ret < 0) - pr_err("failed to initialise WM8971\n"); - + kfree(wm8971); return ret; }
-static int wm8971_i2c_remove(struct i2c_client *client) +static __devexit int wm8971_i2c_remove(struct i2c_client *client) { - struct snd_soc_codec *codec = i2c_get_clientdata(client); - kfree(codec->reg_cache); + snd_soc_unregister_codec(&client->dev, client->addr); + kfree(i2c_get_clientdata(client)); return 0; }
@@ -752,145 +756,31 @@ static struct i2c_driver wm8971_i2c_driver = { .name = "WM8971 I2C Codec", .owner = THIS_MODULE, }, - .probe = wm8971_i2c_probe, - .remove = wm8971_i2c_remove, + .probe = wm8971_i2c_probe, + .remove = __devexit_p(wm8971_i2c_remove), .id_table = wm8971_i2c_id, }; - -static int wm8971_add_i2c_device(struct platform_device *pdev, - const struct wm8971_setup_data *setup) -{ - struct i2c_board_info info; - struct i2c_adapter *adapter; - struct i2c_client *client; - int ret; - - ret = i2c_add_driver(&wm8971_i2c_driver); - if (ret != 0) { - dev_err(&pdev->dev, "can't add i2c driver\n"); - return ret; - } - - memset(&info, 0, sizeof(struct i2c_board_info)); - info.addr = setup->i2c_address; - strlcpy(info.type, "wm8971", I2C_NAME_SIZE); - - adapter = i2c_get_adapter(setup->i2c_bus); - if (!adapter) { - dev_err(&pdev->dev, "can't get i2c adapter %d\n", - setup->i2c_bus); - goto err_driver; - } - - client = i2c_new_device(adapter, &info); - i2c_put_adapter(adapter); - if (!client) { - dev_err(&pdev->dev, "can't add i2c device at 0x%x\n", - (unsigned int)info.addr); - goto err_driver; - } - - return 0; - -err_driver: - i2c_del_driver(&wm8971_i2c_driver); - return -ENODEV; -} - #endif
-static int wm8971_probe(struct platform_device *pdev) +static int __init wm8971_modinit(void) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct wm8971_setup_data *setup; - struct snd_soc_codec *codec; - struct wm8971_priv *wm8971; int ret = 0; - - pr_info("WM8971 Audio Codec %s", WM8971_VERSION); - - setup = socdev->codec_data; - codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); - if (codec == NULL) - return -ENOMEM; - - wm8971 = kzalloc(sizeof(struct wm8971_priv), GFP_KERNEL); - if (wm8971 == NULL) { - kfree(codec); - return -ENOMEM; - } - - snd_soc_codec_set_drvdata(codec, wm8971); - socdev->card->codec = codec; - mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - wm8971_socdev = socdev; - - INIT_DELAYED_WORK(&codec->delayed_work, wm8971_work); - wm8971_workq = create_workqueue("wm8971"); - if (wm8971_workq == NULL) { - kfree(snd_soc_codec_get_drvdata(codec)); - kfree(codec); - return -ENOMEM; - } - -#if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) - if (setup->i2c_address) { - ret = wm8971_add_i2c_device(pdev, setup); - } -#endif - /* Add other interfaces here */ - +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) + ret = i2c_add_driver(&wm8971_i2c_driver); if (ret != 0) { - destroy_workqueue(wm8971_workq); - kfree(snd_soc_codec_get_drvdata(codec)); - kfree(codec); + printk(KERN_ERR "Failed to register WM8971 I2C driver: %d\n", + ret); } - - return ret; -} - -/* power down chip */ -static int wm8971_remove(struct platform_device *pdev) -{ - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - - if (codec->control_data) - wm8971_set_bias_level(codec, SND_SOC_BIAS_OFF); - if (wm8971_workq) - destroy_workqueue(wm8971_workq); - snd_soc_free_pcms(socdev); - snd_soc_dapm_free(socdev); -#if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) - i2c_unregister_device(codec->control_data); - i2c_del_driver(&wm8971_i2c_driver); #endif - kfree(snd_soc_codec_get_drvdata(codec)); - kfree(codec); - - return 0; -} - -struct snd_soc_codec_device soc_codec_dev_wm8971 = { - .probe = wm8971_probe, - .remove = wm8971_remove, - .suspend = wm8971_suspend, - .resume = wm8971_resume, -}; - -EXPORT_SYMBOL_GPL(soc_codec_dev_wm8971); - -static int __init wm8971_modinit(void) -{ - return snd_soc_register_dai(&wm8971_dai); + return ret; } module_init(wm8971_modinit);
static void __exit wm8971_exit(void) { - snd_soc_unregister_dai(&wm8971_dai); +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) + i2c_del_driver(&wm8971_i2c_driver); +#endif } module_exit(wm8971_exit);
diff --git a/sound/soc/codecs/wm8971.h b/sound/soc/codecs/wm8971.h index ef4f08f..a5a3292 100644 --- a/sound/soc/codecs/wm8971.h +++ b/sound/soc/codecs/wm8971.h @@ -53,12 +53,7 @@
#define WM8971_SYSCLK 0
-struct wm8971_setup_data { - int i2c_bus; - unsigned short i2c_address; -}; - -extern struct snd_soc_dai wm8971_dai; -extern struct snd_soc_codec_device soc_codec_dev_wm8971; +extern struct snd_soc_dai_driver wm8971_dai; +extern struct snd_soc_codec_driver soc_codec_dev_wm8971;
#endif diff --git a/sound/soc/codecs/wm8974.c b/sound/soc/codecs/wm8974.c index a2c4b2f..f290fad 100644 --- a/sound/soc/codecs/wm8974.c +++ b/sound/soc/codecs/wm8974.c @@ -51,12 +51,11 @@ static const u16 wm8974_reg[WM8974_CACHEREGNUM] = { #define WM8974_POWER1_BUFIOEN 0x04
struct wm8974_priv { - struct snd_soc_codec codec; + enum snd_soc_control_type control_type; + void *control_data; u16 reg_cache[WM8974_CACHEREGNUM]; };
-static struct snd_soc_codec *wm8974_codec; - #define wm8974_reset(c) snd_soc_write(c, WM8974_RESET, 0)
static const char *wm8974_companding[] = {"Off", "NC", "u-law", "A-law" }; @@ -566,7 +565,7 @@ static struct snd_soc_dai_ops wm8974_ops = { .set_pll = wm8974_set_dai_pll, };
-struct snd_soc_dai wm8974_dai = { +struct snd_soc_dai_driver wm8974_dai = { .name = "WM8974 HiFi", .playback = { .stream_name = "Playback", @@ -585,19 +584,14 @@ struct snd_soc_dai wm8974_dai = { }; EXPORT_SYMBOL_GPL(wm8974_dai);
-static int wm8974_suspend(struct platform_device *pdev, pm_message_t state) +static int wm8974_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; - wm8974_set_bias_level(codec, SND_SOC_BIAS_OFF); return 0; }
-static int wm8974_resume(struct platform_device *pdev) +static int wm8974_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; @@ -613,155 +607,78 @@ static int wm8974_resume(struct platform_device *pdev) return 0; }
-static int wm8974_probe(struct platform_device *pdev) +static int wm8974_probe(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; + struct wm8974_priv *wm8974 = snd_soc_codec_get_drvdata(codec); int ret = 0;
- if (wm8974_codec == NULL) { - dev_err(&pdev->dev, "Codec device not registered\n"); - return -ENODEV; + codec->control_data = wm8974->control_data; + ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_I2C); + if (ret < 0) { + dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); + return ret; }
- socdev->card->codec = wm8974_codec; - codec = wm8974_codec; - - /* register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); + ret = wm8974_reset(codec); if (ret < 0) { - dev_err(codec->dev, "failed to create pcms: %d\n", ret); - goto pcm_err; + dev_err(codec->dev, "Failed to issue reset\n"); + return ret; }
+ wm8974_set_bias_level(codec, SND_SOC_BIAS_STANDBY); snd_soc_add_controls(codec, wm8974_snd_controls, ARRAY_SIZE(wm8974_snd_controls)); wm8974_add_widgets(codec);
return ret; - -pcm_err: - return ret; }
/* power down chip */ -static int wm8974_remove(struct platform_device *pdev) +static int wm8974_remove(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - - snd_soc_free_pcms(socdev); - snd_soc_dapm_free(socdev); - + wm8974_set_bias_level(codec, SND_SOC_BIAS_OFF); return 0; }
-struct snd_soc_codec_device soc_codec_dev_wm8974 = { +struct snd_soc_codec_driver soc_codec_dev_wm8974 = { + .name = "wm8974", + .owner = THIS_MODULE, .probe = wm8974_probe, .remove = wm8974_remove, .suspend = wm8974_suspend, .resume = wm8974_resume, + .set_bias_level = wm8974_set_bias_level, + .reg_cache_size = ARRAY_SIZE(wm8974_reg), + .reg_word_size = sizeof(u16), + .reg_cache_default = wm8974_reg, }; EXPORT_SYMBOL_GPL(soc_codec_dev_wm8974);
-static __devinit int wm8974_register(struct wm8974_priv *wm8974) -{ - int ret; - struct snd_soc_codec *codec = &wm8974->codec; - - if (wm8974_codec) { - dev_err(codec->dev, "Another WM8974 is registered\n"); - return -EINVAL; - } - - mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - snd_soc_codec_set_drvdata(codec, wm8974); - codec->name = "WM8974"; - codec->owner = THIS_MODULE; - codec->bias_level = SND_SOC_BIAS_OFF; - codec->set_bias_level = wm8974_set_bias_level; - codec->dai = &wm8974_dai; - codec->num_dai = 1; - codec->reg_cache_size = WM8974_CACHEREGNUM; - codec->reg_cache = &wm8974->reg_cache; - - ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_I2C); - if (ret < 0) { - dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); - goto err; - } - - memcpy(codec->reg_cache, wm8974_reg, sizeof(wm8974_reg)); - - ret = wm8974_reset(codec); - if (ret < 0) { - dev_err(codec->dev, "Failed to issue reset\n"); - goto err; - } - - wm8974_dai.dev = codec->dev; - - wm8974_set_bias_level(codec, SND_SOC_BIAS_STANDBY); - - wm8974_codec = codec; - - ret = snd_soc_register_codec(codec); - if (ret != 0) { - dev_err(codec->dev, "Failed to register codec: %d\n", ret); - goto err; - } - - ret = snd_soc_register_dai(&wm8974_dai); - if (ret != 0) { - dev_err(codec->dev, "Failed to register DAI: %d\n", ret); - goto err_codec; - } - - return 0; - -err_codec: - snd_soc_unregister_codec(codec); -err: - kfree(wm8974); - return ret; -} - -static __devexit void wm8974_unregister(struct wm8974_priv *wm8974) -{ - wm8974_set_bias_level(&wm8974->codec, SND_SOC_BIAS_OFF); - snd_soc_unregister_dai(&wm8974_dai); - snd_soc_unregister_codec(&wm8974->codec); - kfree(wm8974); - wm8974_codec = NULL; -} - +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) static __devinit int wm8974_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct wm8974_priv *wm8974; - struct snd_soc_codec *codec; + int ret;
wm8974 = kzalloc(sizeof(struct wm8974_priv), GFP_KERNEL); if (wm8974 == NULL) return -ENOMEM;
- codec = &wm8974->codec; - codec->hw_write = (hw_write_t)i2c_master_send; - i2c_set_clientdata(i2c, wm8974); - codec->control_data = i2c; - - codec->dev = &i2c->dev; + wm8974->control_data = i2c;
- return wm8974_register(wm8974); + ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &soc_codec_dev_wm8974, &wm8974_dai, 1); + if (ret < 0) + kfree(wm8974); + return ret; }
static __devexit int wm8974_i2c_remove(struct i2c_client *client) { - struct wm8974_priv *wm8974 = i2c_get_clientdata(client); - wm8974_unregister(wm8974); + snd_soc_unregister_codec(&client->dev, client->addr); + kfree(i2c_get_clientdata(client)); return 0; }
@@ -773,23 +690,34 @@ MODULE_DEVICE_TABLE(i2c, wm8974_i2c_id);
static struct i2c_driver wm8974_i2c_driver = { .driver = { - .name = "WM8974", + .name = "wm8974 I2C Codec", .owner = THIS_MODULE, }, .probe = wm8974_i2c_probe, .remove = __devexit_p(wm8974_i2c_remove), .id_table = wm8974_i2c_id, }; +#endif
static int __init wm8974_modinit(void) { - return i2c_add_driver(&wm8974_i2c_driver); + int ret = 0; +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) + ret = i2c_add_driver(&wm8974_i2c_driver); + if (ret != 0) { + printk(KERN_ERR "Failed to register wm8974 I2C driver: %d\n", + ret); + } +#endif + return ret; } module_init(wm8974_modinit);
static void __exit wm8974_exit(void) { +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) i2c_del_driver(&wm8974_i2c_driver); +#endif } module_exit(wm8974_exit);
diff --git a/sound/soc/codecs/wm8974.h b/sound/soc/codecs/wm8974.h index 896a7f0..636cbe4 100644 --- a/sound/soc/codecs/wm8974.h +++ b/sound/soc/codecs/wm8974.h @@ -83,7 +83,7 @@ #define WM8974_MCLKDIV_8 (6 << 5) #define WM8974_MCLKDIV_12 (7 << 5)
-extern struct snd_soc_dai wm8974_dai; -extern struct snd_soc_codec_device soc_codec_dev_wm8974; +extern struct snd_soc_dai_driver wm8974_dai; +extern struct snd_soc_codec_driver soc_codec_dev_wm8974;
#endif diff --git a/sound/soc/codecs/wm8990.c b/sound/soc/codecs/wm8990.c index dd8d909..426a573 100644 --- a/sound/soc/codecs/wm8990.c +++ b/sound/soc/codecs/wm8990.c @@ -32,6 +32,8 @@
/* codec private data */ struct wm8990_priv { + enum snd_soc_control_type control_type; + void *control_data; unsigned int sysclk; unsigned int pcmclk; }; @@ -1114,8 +1116,7 @@ static int wm8990_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; u16 audio1 = snd_soc_read(codec, WM8990_AUDIO_INTERFACE_1);
audio1 &= ~WM8990_AIF_WL_MASK; @@ -1293,10 +1294,9 @@ static struct snd_soc_dai_ops wm8990_dai_ops = { .set_sysclk = wm8990_set_dai_sysclk, };
-struct snd_soc_dai wm8990_dai = { +struct snd_soc_dai_driver wm8990_dai = { /* ADC/DAC on primary */ .name = "WM8990 ADC/DAC Primary", - .id = 1, .playback = { .stream_name = "Playback", .channels_min = 1, @@ -1313,19 +1313,14 @@ struct snd_soc_dai wm8990_dai = { }; EXPORT_SYMBOL_GPL(wm8990_dai);
-static int wm8990_suspend(struct platform_device *pdev, pm_message_t state) +static int wm8990_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; - wm8990_set_bias_level(codec, SND_SOC_BIAS_OFF); return 0; }
-static int wm8990_resume(struct platform_device *pdev) +static int wm8990_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; @@ -1347,38 +1342,21 @@ static int wm8990_resume(struct platform_device *pdev) * initialise the WM8990 driver * register the mixer and dsp interfaces with the kernel */ -static int wm8990_init(struct snd_soc_device *socdev) +static int wm8990_probe(struct snd_soc_codec *codec) { - struct snd_soc_codec *codec = socdev->card->codec; + struct wm8990_priv *wm8990 = snd_soc_codec_get_drvdata(codec); + int ret; u16 reg; - int ret = 0; - - codec->name = "WM8990"; - codec->owner = THIS_MODULE; - codec->set_bias_level = wm8990_set_bias_level; - codec->dai = &wm8990_dai; - codec->num_dai = 2; - codec->reg_cache_size = ARRAY_SIZE(wm8990_reg); - codec->reg_cache = kmemdup(wm8990_reg, sizeof(wm8990_reg), GFP_KERNEL); - - if (codec->reg_cache == NULL) - return -ENOMEM;
+ codec->control_data = wm8990->control_data; ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_I2C); if (ret < 0) { printk(KERN_ERR "wm8990: failed to set cache I/O: %d\n", ret); - goto pcm_err; + return ret; }
wm8990_reset(codec);
- /* register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret < 0) { - printk(KERN_ERR "wm8990: failed to create pcms\n"); - goto pcm_err; - } - /* charge output caps */ codec->bias_level = SND_SOC_BIAS_OFF; wm8990_set_bias_level(codec, SND_SOC_BIAS_STANDBY); @@ -1400,47 +1378,55 @@ static int wm8990_init(struct snd_soc_device *socdev) ARRAY_SIZE(wm8990_snd_controls)); wm8990_add_widgets(codec);
- return ret; + return 0; +}
-pcm_err: - kfree(codec->reg_cache); - return ret; +/* power down chip */ +static int wm8990_remove(struct snd_soc_codec *codec) +{ + wm8990_set_bias_level(codec, SND_SOC_BIAS_OFF); + return 0; }
-/* If the i2c layer weren't so broken, we could pass this kind of data - around */ -static struct snd_soc_device *wm8990_socdev; +struct snd_soc_codec_driver soc_codec_dev_wm8990 = { + .name = "wm8990", + .owner = THIS_MODULE, + .probe = wm8990_probe, + .remove = wm8990_remove, + .suspend = wm8990_suspend, + .resume = wm8990_resume, + .set_bias_level = wm8990_set_bias_level, + .reg_cache_size = ARRAY_SIZE(wm8990_reg), + .reg_word_size = sizeof(u16), + .reg_cache_default = wm8990_reg, +}; +EXPORT_SYMBOL_GPL(soc_codec_dev_wm8990);
#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) - -/* - * WM891 2 wire address is determined by GPIO5 - * state during powerup. - * low = 0x34 - * high = 0x36 - */ - -static int wm8990_i2c_probe(struct i2c_client *i2c, - const struct i2c_device_id *id) +static __devinit int wm8990_i2c_probe(struct i2c_client *i2c, + const struct i2c_device_id *id) { - struct snd_soc_device *socdev = wm8990_socdev; - struct snd_soc_codec *codec = socdev->card->codec; + struct wm8990_priv *wm8990; int ret;
- i2c_set_clientdata(i2c, codec); - codec->control_data = i2c; + wm8990 = kzalloc(sizeof(struct wm8990_priv), GFP_KERNEL); + if (wm8990 == NULL) + return -ENOMEM;
- ret = wm8990_init(socdev); - if (ret < 0) - pr_err("failed to initialise WM8990\n"); + i2c_set_clientdata(i2c, wm8990); + wm8990->control_data = i2c;
+ ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &soc_codec_dev_wm8990, &wm8990_dai, 1); + if (ret < 0) + kfree(wm8990); return ret; }
-static int wm8990_i2c_remove(struct i2c_client *client) +static __devexit int wm8990_i2c_remove(struct i2c_client *client) { - struct snd_soc_codec *codec = i2c_get_clientdata(client); - kfree(codec->reg_cache); + snd_soc_unregister_codec(&client->dev, client->addr); + kfree(i2c_get_clientdata(client)); return 0; }
@@ -1452,134 +1438,34 @@ MODULE_DEVICE_TABLE(i2c, wm8990_i2c_id);
static struct i2c_driver wm8990_i2c_driver = { .driver = { - .name = "WM8990 I2C Codec", + .name = "wm8990 I2C Codec", .owner = THIS_MODULE, }, .probe = wm8990_i2c_probe, - .remove = wm8990_i2c_remove, + .remove = __devexit_p(wm8990_i2c_remove), .id_table = wm8990_i2c_id, }; - -static int wm8990_add_i2c_device(struct platform_device *pdev, - const struct wm8990_setup_data *setup) -{ - struct i2c_board_info info; - struct i2c_adapter *adapter; - struct i2c_client *client; - int ret; - - ret = i2c_add_driver(&wm8990_i2c_driver); - if (ret != 0) { - dev_err(&pdev->dev, "can't add i2c driver\n"); - return ret; - } - - memset(&info, 0, sizeof(struct i2c_board_info)); - info.addr = setup->i2c_address; - strlcpy(info.type, "wm8990", I2C_NAME_SIZE); - - adapter = i2c_get_adapter(setup->i2c_bus); - if (!adapter) { - dev_err(&pdev->dev, "can't get i2c adapter %d\n", - setup->i2c_bus); - goto err_driver; - } - - client = i2c_new_device(adapter, &info); - i2c_put_adapter(adapter); - if (!client) { - dev_err(&pdev->dev, "can't add i2c device at 0x%x\n", - (unsigned int)info.addr); - goto err_driver; - } - - return 0; - -err_driver: - i2c_del_driver(&wm8990_i2c_driver); - return -ENODEV; -} #endif
-static int wm8990_probe(struct platform_device *pdev) +static int __init wm8990_modinit(void) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct wm8990_setup_data *setup; - struct snd_soc_codec *codec; - struct wm8990_priv *wm8990; - int ret; - - setup = socdev->codec_data; - codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); - if (codec == NULL) - return -ENOMEM; - - wm8990 = kzalloc(sizeof(struct wm8990_priv), GFP_KERNEL); - if (wm8990 == NULL) { - kfree(codec); - return -ENOMEM; - } - - snd_soc_codec_set_drvdata(codec, wm8990); - socdev->card->codec = codec; - mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - wm8990_socdev = socdev; - - ret = -ENODEV; - + int ret = 0; #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) - if (setup->i2c_address) { - codec->hw_write = (hw_write_t)i2c_master_send; - ret = wm8990_add_i2c_device(pdev, setup); - } -#endif - + ret = i2c_add_driver(&wm8990_i2c_driver); if (ret != 0) { - kfree(snd_soc_codec_get_drvdata(codec)); - kfree(codec); + printk(KERN_ERR "Failed to register wm8990 I2C driver: %d\n", + ret); } +#endif return ret; } +module_init(wm8990_modinit);
-/* power down chip */ -static int wm8990_remove(struct platform_device *pdev) +static void __exit wm8990_exit(void) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - - if (codec->control_data) - wm8990_set_bias_level(codec, SND_SOC_BIAS_OFF); - snd_soc_free_pcms(socdev); - snd_soc_dapm_free(socdev); #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) - i2c_unregister_device(codec->control_data); i2c_del_driver(&wm8990_i2c_driver); #endif - kfree(snd_soc_codec_get_drvdata(codec)); - kfree(codec); - - return 0; -} - -struct snd_soc_codec_device soc_codec_dev_wm8990 = { - .probe = wm8990_probe, - .remove = wm8990_remove, - .suspend = wm8990_suspend, - .resume = wm8990_resume, -}; -EXPORT_SYMBOL_GPL(soc_codec_dev_wm8990); - -static int __init wm8990_modinit(void) -{ - return snd_soc_register_dai(&wm8990_dai); -} -module_init(wm8990_modinit); - -static void __exit wm8990_exit(void) -{ - snd_soc_unregister_dai(&wm8990_dai); } module_exit(wm8990_exit);
diff --git a/sound/soc/codecs/wm8990.h b/sound/soc/codecs/wm8990.h index 7114ddc..4c7bede 100644 --- a/sound/soc/codecs/wm8990.h +++ b/sound/soc/codecs/wm8990.h @@ -826,18 +826,13 @@ #define WM8990_INMIXR_PWR_BIT 2 #define WM8990_AINRMUX_PWR_BIT 3
-struct wm8990_setup_data { - unsigned i2c_bus; - unsigned short i2c_address; -}; - #define WM8990_MCLK_DIV 0 #define WM8990_DACCLK_DIV 1 #define WM8990_ADCCLK_DIV 2 #define WM8990_BCLK_DIV 3
-extern struct snd_soc_dai wm8990_dai; -extern struct snd_soc_codec_device soc_codec_dev_wm8990; +extern struct snd_soc_dai_driver wm8990_dai; +extern struct snd_soc_codec_driver soc_codec_dev_wm8990;
#endif /* __WM8990REGISTERDEFS_H__ */ /*------------------------------ END OF FILE ---------------------------------*/ diff --git a/sound/soc/codecs/wm8993.c b/sound/soc/codecs/wm8993.c index d8d300c..6f6a2af 100644 --- a/sound/soc/codecs/wm8993.c +++ b/sound/soc/codecs/wm8993.c @@ -229,7 +229,8 @@ struct wm8993_priv { u16 reg_cache[WM8993_REGISTER_COUNT]; struct regulator_bulk_data supplies[WM8993_NUM_SUPPLIES]; struct wm8993_platform_data pdata; - struct snd_soc_codec codec; + enum snd_soc_control_type control_type; + void *control_data; int master; int sysclk_source; int tdm_slots; @@ -367,10 +368,9 @@ static int fll_factors(struct _fll_div *fll_div, unsigned int Fref, return 0; }
-static int wm8993_set_fll(struct snd_soc_dai *dai, int fll_id, int source, +static int _wm8993_set_fll(struct snd_soc_codec *codec, int fll_id, int source, unsigned int Fref, unsigned int Fout) { - struct snd_soc_codec *codec = dai->codec; struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec); u16 reg1, reg4, reg5; struct _fll_div fll_div; @@ -456,6 +456,12 @@ static int wm8993_set_fll(struct snd_soc_dai *dai, int fll_id, int source, return 0; }
+static int wm8993_set_fll(struct snd_soc_dai *dai, int fll_id, int source, + unsigned int Fref, unsigned int Fout) +{ + return _wm8993_set_fll(dai->codec, fll_id, source, Fref, Fout); +} + static int configure_clock(struct snd_soc_codec *codec) { struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec); @@ -1394,7 +1400,7 @@ static struct snd_soc_dai_ops wm8993_ops = { SNDRV_PCM_FMTBIT_S24_LE |\ SNDRV_PCM_FMTBIT_S32_LE)
-struct snd_soc_dai wm8993_dai = { +struct snd_soc_dai_driver wm8993_dai = { .name = "WM8993", .playback = { .stream_name = "Playback", @@ -1415,30 +1421,81 @@ struct snd_soc_dai wm8993_dai = { }; EXPORT_SYMBOL_GPL(wm8993_dai);
-static struct snd_soc_codec *wm8993_codec; - -static int wm8993_probe(struct platform_device *pdev) +static int wm8993_probe(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - struct wm8993_priv *wm8993; - int ret = 0; + struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec); + int ret, i, val; + + codec->control_data = wm8993->control_data; + wm8993->hubs_data.hp_startup_mode = 1; + wm8993->hubs_data.dcs_codes = -2;
- if (!wm8993_codec) { - dev_err(&pdev->dev, "I2C device not yet probed\n"); - goto err; + ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_I2C); + if (ret != 0) { + dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); + return ret; }
- socdev->card->codec = wm8993_codec; - codec = wm8993_codec; - wm8993 = snd_soc_codec_get_drvdata(codec); + for (i = 0; i < ARRAY_SIZE(wm8993->supplies); i++) + wm8993->supplies[i].supply = wm8993_supply_names[i];
- ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret < 0) { - dev_err(codec->dev, "failed to create pcms\n"); - goto err; + ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(wm8993->supplies), + wm8993->supplies); + if (ret != 0) { + dev_err(codec->dev, "Failed to request supplies: %d\n", ret); + return ret; + } + + ret = regulator_bulk_enable(ARRAY_SIZE(wm8993->supplies), + wm8993->supplies); + if (ret != 0) { + dev_err(codec->dev, "Failed to enable supplies: %d\n", ret); + goto err_get; }
+ val = snd_soc_read(codec, WM8993_SOFTWARE_RESET); + if (val != wm8993_reg_defaults[WM8993_SOFTWARE_RESET]) { + dev_err(codec->dev, "Invalid ID register value %x\n", val); + ret = -EINVAL; + goto err_enable; + } + + ret = snd_soc_write(codec, WM8993_SOFTWARE_RESET, 0xffff); + if (ret != 0) + goto err_enable; + + codec->cache_only = 1; + + /* By default we're using the output mixers */ + wm8993->class_w_users = 2; + + /* Latch volume update bits and default ZC on */ + snd_soc_update_bits(codec, WM8993_RIGHT_DAC_DIGITAL_VOLUME, + WM8993_DAC_VU, WM8993_DAC_VU); + snd_soc_update_bits(codec, WM8993_RIGHT_ADC_DIGITAL_VOLUME, + WM8993_ADC_VU, WM8993_ADC_VU); + + /* Manualy manage the HPOUT sequencing for independent stereo + * control. */ + snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0, + WM8993_HPOUT1_AUTO_PU, 0); + + /* Use automatic clock configuration */ + snd_soc_update_bits(codec, WM8993_CLOCKING_4, WM8993_SR_MODE, 0); + + wm_hubs_handle_analogue_pdata(codec, wm8993->pdata.lineout1_diff, + wm8993->pdata.lineout2_diff, + wm8993->pdata.lineout1fb, + wm8993->pdata.lineout2fb, + wm8993->pdata.jd_scthr, + wm8993->pdata.jd_thr, + wm8993->pdata.micbias1_lvl, + wm8993->pdata.micbias2_lvl); + + ret = wm8993_set_bias_level(codec, SND_SOC_BIAS_STANDBY); + if (ret != 0) + goto err_enable; + snd_soc_add_controls(codec, wm8993_snd_controls, ARRAY_SIZE(wm8993_snd_controls)); if (wm8993->pdata.num_retune_configs != 0) { @@ -1457,36 +1514,36 @@ static int wm8993_probe(struct platform_device *pdev) wm_hubs_add_analogue_routes(codec, wm8993->pdata.lineout1_diff, wm8993->pdata.lineout2_diff);
- return ret; + return 0;
-err: +err_enable: + regulator_bulk_disable(ARRAY_SIZE(wm8993->supplies), wm8993->supplies); +err_get: + regulator_bulk_free(ARRAY_SIZE(wm8993->supplies), wm8993->supplies); return ret; }
-static int wm8993_remove(struct platform_device *pdev) +static int wm8993_remove(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - - snd_soc_free_pcms(socdev); - snd_soc_dapm_free(socdev); + struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec);
+ wm8993_set_bias_level(codec, SND_SOC_BIAS_OFF); + regulator_bulk_free(ARRAY_SIZE(wm8993->supplies), wm8993->supplies); return 0; }
#ifdef CONFIG_PM -static int wm8993_suspend(struct platform_device *pdev, pm_message_t state) +static int wm8993_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; struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec); int fll_fout = wm8993->fll_fout; int fll_fref = wm8993->fll_fref; int ret;
/* Stop the FLL in an orderly fashion */ - ret = wm8993_set_fll(codec->dai, 0, 0, 0, 0); + ret = _wm8993_set_fll(codec, 0, 0, 0, 0); if (ret != 0) { - dev_err(&pdev->dev, "Failed to stop FLL\n"); + dev_err(codec->dev, "Failed to stop FLL\n"); return ret; }
@@ -1498,10 +1555,8 @@ static int wm8993_suspend(struct platform_device *pdev, pm_message_t state) return 0; }
-static int wm8993_resume(struct platform_device *pdev) +static int wm8993_resume(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec); int ret;
@@ -1515,7 +1570,7 @@ static int wm8993_resume(struct platform_device *pdev) wm8993->fll_fref = 0; wm8993->fll_fout = 0;
- ret = wm8993_set_fll(codec->dai, 0, wm8993->fll_src, + ret = _wm8993_set_fll(codec, 0, wm8993->fll_src, fll_fref, fll_fout); if (ret != 0) dev_err(codec->dev, "Failed to restart FLL\n"); @@ -1528,162 +1583,46 @@ static int wm8993_resume(struct platform_device *pdev) #define wm8993_resume NULL #endif
-struct snd_soc_codec_device soc_codec_dev_wm8993 = { +struct snd_soc_codec_driver soc_codec_dev_wm8993 = { + .name = "wm8993", + .owner = THIS_MODULE, .probe = wm8993_probe, .remove = wm8993_remove, - .suspend = wm8993_suspend, + .suspend = wm8993_suspend, .resume = wm8993_resume, + .set_bias_level = wm8993_set_bias_level, + .reg_cache_size = sizeof(wm8993_reg_defaults), + .reg_word_size = sizeof(u16), + .reg_cache_default = wm8993_reg_defaults, + .volatile_register = wm8993_volatile, }; EXPORT_SYMBOL_GPL(soc_codec_dev_wm8993);
-static int wm8993_i2c_probe(struct i2c_client *i2c, - const struct i2c_device_id *id) +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) +static __devinit int wm8993_i2c_probe(struct i2c_client *i2c, + const struct i2c_device_id *id) { struct wm8993_priv *wm8993; - struct snd_soc_codec *codec; - unsigned int val; int ret; - int i; - - if (wm8993_codec) { - dev_err(&i2c->dev, "A WM8993 is already registered\n"); - return -EINVAL; - }
wm8993 = kzalloc(sizeof(struct wm8993_priv), GFP_KERNEL); if (wm8993 == NULL) return -ENOMEM;
- codec = &wm8993->codec; - if (i2c->dev.platform_data) - memcpy(&wm8993->pdata, i2c->dev.platform_data, - sizeof(wm8993->pdata)); - - mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - codec->name = "WM8993"; - codec->volatile_register = wm8993_volatile; - codec->reg_cache = wm8993->reg_cache; - codec->reg_cache_size = ARRAY_SIZE(wm8993->reg_cache); - codec->bias_level = SND_SOC_BIAS_OFF; - codec->set_bias_level = wm8993_set_bias_level; - codec->dai = &wm8993_dai; - codec->num_dai = 1; - snd_soc_codec_set_drvdata(codec, wm8993); - - wm8993->hubs_data.hp_startup_mode = 1; - wm8993->hubs_data.dcs_codes = -2; - - memcpy(wm8993->reg_cache, wm8993_reg_defaults, - sizeof(wm8993->reg_cache)); - - ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_I2C); - if (ret != 0) { - dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); - goto err; - } - i2c_set_clientdata(i2c, wm8993); - codec->control_data = i2c; - wm8993_codec = codec; - - codec->dev = &i2c->dev; - - for (i = 0; i < ARRAY_SIZE(wm8993->supplies); i++) - wm8993->supplies[i].supply = wm8993_supply_names[i]; - - ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(wm8993->supplies), - wm8993->supplies); - if (ret != 0) { - dev_err(codec->dev, "Failed to request supplies: %d\n", ret); - goto err; - } - - ret = regulator_bulk_enable(ARRAY_SIZE(wm8993->supplies), - wm8993->supplies); - if (ret != 0) { - dev_err(codec->dev, "Failed to enable supplies: %d\n", ret); - goto err_get; - } - - val = snd_soc_read(codec, WM8993_SOFTWARE_RESET); - if (val != wm8993_reg_defaults[WM8993_SOFTWARE_RESET]) { - dev_err(codec->dev, "Invalid ID register value %x\n", val); - ret = -EINVAL; - goto err_enable; - } - - ret = snd_soc_write(codec, WM8993_SOFTWARE_RESET, 0xffff); - if (ret != 0) - goto err_enable; - - codec->cache_only = 1; - - /* By default we're using the output mixers */ - wm8993->class_w_users = 2; - - /* Latch volume update bits and default ZC on */ - snd_soc_update_bits(codec, WM8993_RIGHT_DAC_DIGITAL_VOLUME, - WM8993_DAC_VU, WM8993_DAC_VU); - snd_soc_update_bits(codec, WM8993_RIGHT_ADC_DIGITAL_VOLUME, - WM8993_ADC_VU, WM8993_ADC_VU); - - /* Manualy manage the HPOUT sequencing for independent stereo - * control. */ - snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0, - WM8993_HPOUT1_AUTO_PU, 0); - - /* Use automatic clock configuration */ - snd_soc_update_bits(codec, WM8993_CLOCKING_4, WM8993_SR_MODE, 0); - - wm_hubs_handle_analogue_pdata(codec, wm8993->pdata.lineout1_diff, - wm8993->pdata.lineout2_diff, - wm8993->pdata.lineout1fb, - wm8993->pdata.lineout2fb, - wm8993->pdata.jd_scthr, - wm8993->pdata.jd_thr, - wm8993->pdata.micbias1_lvl, - wm8993->pdata.micbias2_lvl); - - ret = wm8993_set_bias_level(codec, SND_SOC_BIAS_STANDBY); - if (ret != 0) - goto err_enable; - - wm8993_dai.dev = codec->dev; - - ret = snd_soc_register_dai(&wm8993_dai); - if (ret != 0) - goto err_bias; + wm8993->control_data = i2c;
- ret = snd_soc_register_codec(codec); - - return 0; - -err_bias: - wm8993_set_bias_level(codec, SND_SOC_BIAS_OFF); -err_enable: - regulator_bulk_disable(ARRAY_SIZE(wm8993->supplies), wm8993->supplies); -err_get: - regulator_bulk_free(ARRAY_SIZE(wm8993->supplies), wm8993->supplies); -err: - wm8993_codec = NULL; - kfree(wm8993); + ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &soc_codec_dev_wm8993, &wm8993_dai, 1); + if (ret < 0) + kfree(wm8993); return ret; }
-static int wm8993_i2c_remove(struct i2c_client *client) +static __devexit int wm8993_i2c_remove(struct i2c_client *client) { - struct wm8993_priv *wm8993 = i2c_get_clientdata(client); - - snd_soc_unregister_codec(&wm8993->codec); - snd_soc_unregister_dai(&wm8993_dai); - - wm8993_set_bias_level(&wm8993->codec, SND_SOC_BIAS_OFF); - regulator_bulk_free(ARRAY_SIZE(wm8993->supplies), wm8993->supplies); - kfree(wm8993); - + snd_soc_unregister_codec(&client->dev, client->addr); + kfree(i2c_get_clientdata(client)); return 0; }
@@ -1698,27 +1637,31 @@ static struct i2c_driver wm8993_i2c_driver = { .name = "WM8993", .owner = THIS_MODULE, }, - .probe = wm8993_i2c_probe, - .remove = wm8993_i2c_remove, + .probe = wm8993_i2c_probe, + .remove = __devexit_p(wm8993_i2c_remove), .id_table = wm8993_i2c_id, }; - +#endif
static int __init wm8993_modinit(void) { - int ret; - + int ret = 0; +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) ret = i2c_add_driver(&wm8993_i2c_driver); - if (ret != 0) - pr_err("WM8993: Unable to register I2C driver: %d\n", ret); - + if (ret != 0) { + pr_err("WM8993: Unable to register I2C driver: %d\n", + ret); + } +#endif return ret; } module_init(wm8993_modinit);
static void __exit wm8993_exit(void) { +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) i2c_del_driver(&wm8993_i2c_driver); +#endif } module_exit(wm8993_exit);
diff --git a/sound/soc/codecs/wm8993.h b/sound/soc/codecs/wm8993.h index 30e71ca..33b5fa3 100644 --- a/sound/soc/codecs/wm8993.h +++ b/sound/soc/codecs/wm8993.h @@ -1,8 +1,8 @@ #ifndef WM8993_H #define WM8993_H
-extern struct snd_soc_dai wm8993_dai; -extern struct snd_soc_codec_device soc_codec_dev_wm8993; +extern struct snd_soc_dai_driver wm8993_dai; +extern struct snd_soc_codec_driver soc_codec_dev_wm8993;
#define WM8993_SYSCLK_MCLK 1 #define WM8993_SYSCLK_FLL 2
Move to Wolfson CODECs to multi-component model.
This patch changes the probe() and remove() of the CODEC drivers as follows:-
o Make CODEC driver a platform device (non MFD codecs only) o Moved all struct snd_soc_codec list, mutex, etc initialiasation to core. o Removed all static codec pointers (drivers now support > 1 codec dev) o snd_soc_register_pcms() now done by core. o snd_soc_register_dai() folded into snd_soc_register_codec(). o codec cache can now be malloc()ed by core.
Other required changes due to multi-component model :-
o wm8994: set_fll() needs to be accessed from both codec and dai device context, so wrapper added to acces from dai context.
Signed-off-by: Liam Girdwood lrg@slimlogic.co.uk --- sound/soc/codecs/wm8978.c | 192 ++++++++++---------------------- sound/soc/codecs/wm8978.h | 4 +- sound/soc/codecs/wm8988.c | 267 ++++++++++++++++----------------------------- sound/soc/codecs/wm8988.h | 4 +- sound/soc/codecs/wm8994.c | 225 +++++++++++++------------------------- sound/soc/codecs/wm8994.h | 4 +- 6 files changed, 234 insertions(+), 462 deletions(-)
diff --git a/sound/soc/codecs/wm8978.c b/sound/soc/codecs/wm8978.c index 51d5f43..f8f69eb 100644 --- a/sound/soc/codecs/wm8978.c +++ b/sound/soc/codecs/wm8978.c @@ -31,8 +31,6 @@
#include "wm8978.h"
-static struct snd_soc_codec *wm8978_codec; - /* wm8978 register cache. Note that register 0 is not included in the cache. */ static const u16 wm8978_reg[WM8978_CACHEREGNUM] = { 0x0000, 0x0000, 0x0000, 0x0000, /* 0x00...0x03 */ @@ -54,7 +52,8 @@ static const u16 wm8978_reg[WM8978_CACHEREGNUM] = {
/* codec private data */ struct wm8978_priv { - struct snd_soc_codec codec; + enum snd_soc_control_type control_type; + void *control_data; unsigned int f_pllout; unsigned int f_mclk; unsigned int f_256fs; @@ -374,8 +373,8 @@ struct wm8978_pll_div {
#define FIXED_PLL_SIZE (1 << 24)
-static void pll_factors(struct wm8978_pll_div *pll_div, unsigned int target, - unsigned int source) +static void pll_factors(struct snd_soc_codec *codec, + struct wm8978_pll_div *pll_div, unsigned int target, unsigned int source) { u64 k_part; unsigned int k, n_div, n_mod; @@ -390,7 +389,7 @@ static void pll_factors(struct wm8978_pll_div *pll_div, unsigned int target, }
if (n_div < 6 || n_div > 12) - dev_warn(wm8978_codec->dev, + dev_warn(codec->dev, "WM8978 N value exceeds recommended range! N = %u\n", n_div);
@@ -505,7 +504,7 @@ static int wm8978_configure_pll(struct snd_soc_codec *codec) dev_dbg(codec->dev, "%s: f_MCLK=%uHz, f_PLLOUT=%uHz\n", __func__, wm8978->f_mclk, wm8978->f_pllout);
- pll_factors(&pll_div, f2, wm8978->f_mclk); + pll_factors(codec, &pll_div, f2, wm8978->f_mclk);
dev_dbg(codec->dev, "%s: calculated PLL N=0x%x, K=0x%x, div2=%d\n", __func__, pll_div.n, pll_div.k, pll_div.div2); @@ -690,8 +689,7 @@ static int wm8978_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 wm8978_priv *wm8978 = snd_soc_codec_get_drvdata(codec); /* Word length mask = 0x60 */ u16 iface_ctl = snd_soc_read(codec, WM8978_AUDIO_INTERFACE) & ~0x60; @@ -875,9 +873,8 @@ static struct snd_soc_dai_ops wm8978_dai_ops = { };
/* Also supports 12kHz */ -struct snd_soc_dai wm8978_dai = { +struct snd_soc_dai_driver wm8978_dai = { .name = "WM8978 HiFi", - .id = 1, .playback = { .stream_name = "Playback", .channels_min = 1, @@ -896,11 +893,8 @@ struct snd_soc_dai wm8978_dai = { }; EXPORT_SYMBOL_GPL(wm8978_dai);
-static int wm8978_suspend(struct platform_device *pdev, pm_message_t state) +static int wm8978_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; - wm8978_set_bias_level(codec, SND_SOC_BIAS_OFF); /* Also switch PLL off */ snd_soc_write(codec, WM8978_POWER_MANAGEMENT_1, 0); @@ -908,10 +902,8 @@ static int wm8978_suspend(struct platform_device *pdev, pm_message_t state) return 0; }
-static int wm8978_resume(struct platform_device *pdev) +static int wm8978_resume(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; struct wm8978_priv *wm8978 = snd_soc_codec_get_drvdata(codec); int i; u16 *cache = codec->reg_cache; @@ -933,54 +925,6 @@ static int wm8978_resume(struct platform_device *pdev) return 0; }
-static int wm8978_probe(struct platform_device *pdev) -{ - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - int ret = 0; - - if (wm8978_codec == NULL) { - dev_err(&pdev->dev, "Codec device not registered\n"); - return -ENODEV; - } - - socdev->card->codec = wm8978_codec; - codec = wm8978_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, wm8978_snd_controls, - ARRAY_SIZE(wm8978_snd_controls)); - wm8978_add_widgets(codec); - -pcm_err: - return ret; -} - -/* power down chip */ -static int wm8978_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_wm8978 = { - .probe = wm8978_probe, - .remove = wm8978_remove, - .suspend = wm8978_suspend, - .resume = wm8978_resume, -}; -EXPORT_SYMBOL_GPL(soc_codec_dev_wm8978); - /* * These registers contain an "update" bit - bit 8. This means, for example, * that one can write new DAC digital volume for both channels, but only when @@ -1000,44 +944,23 @@ static const int update_reg[] = { WM8978_ROUT2_SPK_CONTROL, };
-static __devinit int wm8978_register(struct wm8978_priv *wm8978) +static int wm8978_probe(struct snd_soc_codec *codec) { - int ret, i; - struct snd_soc_codec *codec = &wm8978->codec; - - if (wm8978_codec) { - dev_err(codec->dev, "Another WM8978 is registered\n"); - return -EINVAL; - } + struct wm8978_priv *wm8978 = snd_soc_codec_get_drvdata(codec); + int ret = 0, i;
/* * Set default system clock to PLL, it is more precise, this is also the * default hardware setting */ wm8978->sysclk = WM8978_PLL; - - mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - snd_soc_codec_set_drvdata(codec, wm8978); - codec->name = "WM8978"; - codec->owner = THIS_MODULE; - codec->bias_level = SND_SOC_BIAS_OFF; - codec->set_bias_level = wm8978_set_bias_level; - codec->dai = &wm8978_dai; - codec->num_dai = 1; - codec->reg_cache_size = WM8978_CACHEREGNUM; - codec->reg_cache = &wm8978->reg_cache; - + codec->control_data = wm8978->control_data; ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_I2C); if (ret < 0) { dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); - goto err; + return ret; }
- memcpy(codec->reg_cache, wm8978_reg, sizeof(wm8978_reg)); - /* * Set the update bit in all registers, that have one. This way all * writes to those registers will also cause the update bit to be @@ -1050,70 +973,64 @@ static __devinit int wm8978_register(struct wm8978_priv *wm8978) ret = snd_soc_write(codec, WM8978_RESET, 0); if (ret < 0) { dev_err(codec->dev, "Failed to issue reset\n"); - goto err; + return ret; }
- wm8978_dai.dev = codec->dev; - wm8978_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
- wm8978_codec = codec; - - ret = snd_soc_register_codec(codec); - if (ret != 0) { - dev_err(codec->dev, "Failed to register codec: %d\n", ret); - goto err; - } - - ret = snd_soc_register_dai(&wm8978_dai); - if (ret != 0) { - dev_err(codec->dev, "Failed to register DAI: %d\n", ret); - goto err_codec; - } + snd_soc_add_controls(codec, wm8978_snd_controls, + ARRAY_SIZE(wm8978_snd_controls)); + wm8978_add_widgets(codec);
return 0; - -err_codec: - snd_soc_unregister_codec(codec); -err: - kfree(wm8978); - return ret; }
-static __devexit void wm8978_unregister(struct wm8978_priv *wm8978) +/* power down chip */ +static int wm8978_remove(struct snd_soc_codec *codec) { - wm8978_set_bias_level(&wm8978->codec, SND_SOC_BIAS_OFF); - snd_soc_unregister_dai(&wm8978_dai); - snd_soc_unregister_codec(&wm8978->codec); - kfree(wm8978); - wm8978_codec = NULL; + wm8978_set_bias_level(codec, SND_SOC_BIAS_OFF); + return 0; }
+struct snd_soc_codec_driver soc_codec_dev_wm8978 = { + .name = "wm8978", + .owner = THIS_MODULE, + .probe = wm8978_probe, + .remove = wm8978_remove, + .suspend = wm8978_suspend, + .resume = wm8978_resume, + .set_bias_level = wm8978_set_bias_level, + .reg_cache_size = ARRAY_SIZE(wm8978_reg), + .reg_word_size = sizeof(u16), + .reg_cache_default = wm8978_reg, +}; +EXPORT_SYMBOL_GPL(soc_codec_dev_wm8978); + +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) static __devinit int wm8978_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct wm8978_priv *wm8978; - struct snd_soc_codec *codec; + int ret;
wm8978 = kzalloc(sizeof(struct wm8978_priv), GFP_KERNEL); if (wm8978 == NULL) return -ENOMEM;
- codec = &wm8978->codec; - codec->hw_write = (hw_write_t)i2c_master_send; - i2c_set_clientdata(i2c, wm8978); - codec->control_data = i2c; - - codec->dev = &i2c->dev; + wm8978->control_data = i2c;
- return wm8978_register(wm8978); + ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &soc_codec_dev_wm8978, &wm8978_dai, 1); + if (ret < 0) + kfree(wm8978); + return ret; }
static __devexit int wm8978_i2c_remove(struct i2c_client *client) { - struct wm8978_priv *wm8978 = i2c_get_clientdata(client); - wm8978_unregister(wm8978); + snd_soc_unregister_codec(&client->dev, client->addr); + kfree(i2c_get_clientdata(client)); return 0; }
@@ -1125,23 +1042,34 @@ MODULE_DEVICE_TABLE(i2c, wm8978_i2c_id);
static struct i2c_driver wm8978_i2c_driver = { .driver = { - .name = "WM8978", + .name = "WM8978 I2C Codec", .owner = THIS_MODULE, }, .probe = wm8978_i2c_probe, .remove = __devexit_p(wm8978_i2c_remove), .id_table = wm8978_i2c_id, }; +#endif
static int __init wm8978_modinit(void) { - return i2c_add_driver(&wm8978_i2c_driver); + int ret = 0; +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) + ret = i2c_add_driver(&wm8978_i2c_driver); + if (ret != 0) { + printk(KERN_ERR "Failed to register WM8978 I2C driver: %d\n", + ret); + } +#endif + return ret; } module_init(wm8978_modinit);
static void __exit wm8978_exit(void) { +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) i2c_del_driver(&wm8978_i2c_driver); +#endif } module_exit(wm8978_exit);
diff --git a/sound/soc/codecs/wm8978.h b/sound/soc/codecs/wm8978.h index 56ec832..bdc5fcc 100644 --- a/sound/soc/codecs/wm8978.h +++ b/sound/soc/codecs/wm8978.h @@ -80,7 +80,7 @@ enum wm8978_sysclk_src { WM8978_MCLK };
-extern struct snd_soc_dai wm8978_dai; -extern struct snd_soc_codec_device soc_codec_dev_wm8978; +extern struct snd_soc_dai_driver wm8978_dai; +extern struct snd_soc_codec_driver soc_codec_dev_wm8978;
#endif /* __WM8978_H__ */ diff --git a/sound/soc/codecs/wm8988.c b/sound/soc/codecs/wm8988.c index 0417dae..e97e1ea 100644 --- a/sound/soc/codecs/wm8988.c +++ b/sound/soc/codecs/wm8988.c @@ -52,7 +52,8 @@ 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; + void *control_data; struct snd_pcm_hw_constraint_list *sysclk_constraints; u16 reg_cache[WM8988_NUM_REG]; }; @@ -608,8 +609,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,7 +711,7 @@ static struct snd_soc_dai_ops wm8988_ops = { .digital_mute = wm8988_mute, };
-struct snd_soc_dai wm8988_dai = { +struct snd_soc_dai_driver wm8988_dai = { .name = "WM8988", .playback = { .stream_name = "Playback", @@ -732,19 +732,14 @@ struct snd_soc_dai wm8988_dai = { }; 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 +758,23 @@ 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); + codec->control_data = wm8988->control_data; + 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,140 +789,138 @@ 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); - snd_soc_unregister_codec(codec); - 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) +struct snd_soc_codec_driver soc_codec_dev_wm8988 = { + .name = "wm8988", + .probe = wm8988_probe, + .remove = wm8988_remove, + .suspend = wm8988_suspend, + .resume = wm8988_resume, + .owner = THIS_MODULE, + .set_bias_level = wm8988_set_bias_level, + .reg_cache_size = sizeof(wm8988_reg), + .reg_word_size = sizeof(u16), + .reg_cache_default = wm8988_reg, +}; +EXPORT_SYMBOL_GPL(soc_codec_dev_wm8988); + +#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; + wm8988->control_data = spi; + wm8988->control_type = SND_SOC_SPI; + spi_set_drvdata(spi, wm8988);
- i2c_set_clientdata(i2c, wm8988); - codec->control_data = i2c; - - codec->dev = &i2c->dev; - - return wm8988_register(wm8988, SND_SOC_I2C); + ret = snd_soc_register_codec(&spi->dev, spi->chip_select, + &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, spi->chip_select); + 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", + .bus = &spi_bus_type, + .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_data = i2c; + wm8988->control_type = SND_SOC_I2C;
- return wm8988_register(wm8988, SND_SOC_SPI); + ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &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, client->addr); + 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 I2C 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; } diff --git a/sound/soc/codecs/wm8988.h b/sound/soc/codecs/wm8988.h index 4552d37..f5a8f7e 100644 --- a/sound/soc/codecs/wm8988.h +++ b/sound/soc/codecs/wm8988.h @@ -54,7 +54,7 @@
#define WM8988_SYSCLK 0
-extern struct snd_soc_dai wm8988_dai; -extern struct snd_soc_codec_device soc_codec_dev_wm8988; +extern struct snd_soc_dai_driver wm8988_dai; +extern struct snd_soc_codec_driver soc_codec_dev_wm8988;
#endif diff --git a/sound/soc/codecs/wm8994.c b/sound/soc/codecs/wm8994.c index e84a117..0dce4a3 100644 --- a/sound/soc/codecs/wm8994.c +++ b/sound/soc/codecs/wm8994.c @@ -36,9 +36,6 @@ #include "wm8994.h" #include "wm_hubs.h"
-static struct snd_soc_codec *wm8994_codec; -struct snd_soc_codec_device soc_codec_dev_wm8994; - struct fll_config { int src; int in; @@ -71,7 +68,9 @@ struct wm8994_micdet { /* codec private data */ struct wm8994_priv { struct wm_hubs_data hubs; - struct snd_soc_codec codec; + enum snd_soc_control_type control_type; + void *control_data; + struct snd_soc_codec *codec; u16 reg_cache[WM8994_REG_CACHE_SIZE + 1]; int sysclk[2]; int sysclk_rate[2]; @@ -1881,8 +1880,6 @@ static int wm8994_put_drc_sw(struct snd_kcontrol *kcontrol, return snd_soc_put_volsw(kcontrol, ucontrol); }
- - static void wm8994_set_drc(struct snd_soc_codec *codec, int drc) { struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); @@ -1921,7 +1918,7 @@ static int wm8994_put_drc_enum(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); - struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); + struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); struct wm8994_pdata *pdata = wm8994->pdata; int drc = wm8994_get_drc(kcontrol->id.name); int value = ucontrol->value.integer.value[0]; @@ -2024,7 +2021,7 @@ static int wm8994_put_retune_mobile_enum(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); - struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); + struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); struct wm8994_pdata *pdata = wm8994->pdata; int block = wm8994_get_retune_mobile_block(kcontrol->id.name); int value = ucontrol->value.integer.value[0]; @@ -2046,7 +2043,7 @@ static int wm8994_get_retune_mobile_enum(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); - struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); + struct wm8994_priv *wm8994 =snd_soc_codec_get_drvdata(codec); int block = wm8994_get_retune_mobile_block(kcontrol->id.name);
ucontrol->value.enumerated.item[0] = wm8994->retune_mobile_cfg[block]; @@ -2832,10 +2829,9 @@ static int wm8994_get_fll_config(struct fll_div *fll, return 0; }
-static int wm8994_set_fll(struct snd_soc_dai *dai, int id, int src, +static int _wm8994_set_fll(struct snd_soc_codec *codec, int id, int src, unsigned int freq_in, unsigned int freq_out) { - struct snd_soc_codec *codec = dai->codec; struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); int reg_offset, ret; struct fll_div fll; @@ -2946,6 +2942,12 @@ static int wm8994_set_fll(struct snd_soc_dai *dai, int id, int src, return 0; }
+static int wm8994_set_fll(struct snd_soc_dai *dai, int id, int src, + unsigned int freq_in, unsigned int freq_out) +{ + return _wm8994_set_fll(dai->codec, id, src, freq_in, freq_out); +} + static int wm8994_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id, unsigned int freq, int dir) { @@ -3437,10 +3439,9 @@ static struct snd_soc_dai_ops wm8994_aif3_dai_ops = { .set_tristate = wm8994_set_tristate, };
-struct snd_soc_dai wm8994_dai[] = { +struct snd_soc_dai_driver wm8994_dai[] = { { .name = "WM8994 AIF1", - .id = 1, .playback = { .stream_name = "AIF1 Playback", .channels_min = 2, @@ -3459,7 +3460,6 @@ struct snd_soc_dai wm8994_dai[] = { }, { .name = "WM8994 AIF2", - .id = 2, .playback = { .stream_name = "AIF2 Playback", .channels_min = 2, @@ -3478,7 +3478,6 @@ struct snd_soc_dai wm8994_dai[] = { }, { .name = "WM8994 AIF3", - .id = 3, .playback = { .stream_name = "AIF3 Playback", .channels_min = 2, @@ -3499,17 +3498,15 @@ struct snd_soc_dai wm8994_dai[] = { EXPORT_SYMBOL_GPL(wm8994_dai);
#ifdef CONFIG_PM -static int wm8994_suspend(struct platform_device *pdev, pm_message_t state) +static int wm8994_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; struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); int i, ret;
for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) { memcpy(&wm8994->fll_suspend[i], &wm8994->fll[i], sizeof(struct fll_config)); - ret = wm8994_set_fll(&codec->dai[0], i + 1, 0, 0, 0); + ret = _wm8994_set_fll(codec, i + 1, 0, 0, 0); if (ret < 0) dev_warn(codec->dev, "Failed to stop FLL%d: %d\n", i + 1, ret); @@ -3520,10 +3517,8 @@ static int wm8994_suspend(struct platform_device *pdev, pm_message_t state) return 0; }
-static int wm8994_resume(struct platform_device *pdev) +static int wm8994_resume(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); u16 *reg_cache = codec->reg_cache; int i, ret; @@ -3552,7 +3547,7 @@ static int wm8994_resume(struct platform_device *pdev) if (!wm8994->fll_suspend[i].out) continue;
- ret = wm8994_set_fll(&codec->dai[0], i + 1, + ret = _wm8994_set_fll(codec, i + 1, wm8994->fll_suspend[i].src, wm8994->fll_suspend[i].in, wm8994->fll_suspend[i].out); @@ -3570,7 +3565,7 @@ static int wm8994_resume(struct platform_device *pdev)
static void wm8994_handle_retune_mobile_pdata(struct wm8994_priv *wm8994) { - struct snd_soc_codec *codec = &wm8994->codec; + struct snd_soc_codec *codec = wm8994->codec; struct wm8994_pdata *pdata = wm8994->pdata; struct snd_kcontrol_new controls[] = { SOC_ENUM_EXT("AIF1.1 EQ Mode", @@ -3628,16 +3623,16 @@ static void wm8994_handle_retune_mobile_pdata(struct wm8994_priv *wm8994) wm8994->retune_mobile_enum.max = wm8994->num_retune_mobile_texts; wm8994->retune_mobile_enum.texts = wm8994->retune_mobile_texts;
- ret = snd_soc_add_controls(&wm8994->codec, controls, + ret = snd_soc_add_controls(wm8994->codec, controls, ARRAY_SIZE(controls)); if (ret != 0) - dev_err(wm8994->codec.dev, + dev_err(wm8994->codec->dev, "Failed to add ReTune Mobile controls: %d\n", ret); }
static void wm8994_handle_pdata(struct wm8994_priv *wm8994) { - struct snd_soc_codec *codec = &wm8994->codec; + struct snd_soc_codec *codec = wm8994->codec; struct wm8994_pdata *pdata = wm8994->pdata; int ret, i;
@@ -3669,7 +3664,7 @@ static void wm8994_handle_pdata(struct wm8994_priv *wm8994) wm8994->drc_texts = kmalloc(sizeof(char *) * pdata->num_drc_cfgs, GFP_KERNEL); if (!wm8994->drc_texts) { - dev_err(wm8994->codec.dev, + dev_err(wm8994->codec->dev, "Failed to allocate %d DRC config texts\n", pdata->num_drc_cfgs); return; @@ -3681,10 +3676,10 @@ static void wm8994_handle_pdata(struct wm8994_priv *wm8994) wm8994->drc_enum.max = pdata->num_drc_cfgs; wm8994->drc_enum.texts = wm8994->drc_texts;
- ret = snd_soc_add_controls(&wm8994->codec, controls, + ret = snd_soc_add_controls(wm8994->codec, controls, ARRAY_SIZE(controls)); if (ret != 0) - dev_err(wm8994->codec.dev, + dev_err(wm8994->codec->dev, "Failed to add DRC mode controls: %d\n", ret);
for (i = 0; i < WM8994_NUM_DRC; i++) @@ -3697,62 +3692,10 @@ static void wm8994_handle_pdata(struct wm8994_priv *wm8994) if (pdata->num_retune_mobile_cfgs) wm8994_handle_retune_mobile_pdata(wm8994); else - snd_soc_add_controls(&wm8994->codec, wm8994_eq_controls, + snd_soc_add_controls(wm8994->codec, wm8994_eq_controls, ARRAY_SIZE(wm8994_eq_controls)); }
-static int wm8994_probe(struct platform_device *pdev) -{ - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - int ret = 0; - - if (wm8994_codec == NULL) { - dev_err(&pdev->dev, "Codec device not registered\n"); - return -ENODEV; - } - - socdev->card->codec = wm8994_codec; - codec = wm8994_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); - return ret; - } - - wm8994_handle_pdata(snd_soc_codec_get_drvdata(codec)); - - wm_hubs_add_analogue_controls(codec); - snd_soc_add_controls(codec, wm8994_snd_controls, - ARRAY_SIZE(wm8994_snd_controls)); - snd_soc_dapm_new_controls(codec, wm8994_dapm_widgets, - ARRAY_SIZE(wm8994_dapm_widgets)); - wm_hubs_add_analogue_routes(codec, 0, 0); - snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon)); - - return 0; -} - -static int wm8994_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_wm8994 = { - .probe = wm8994_probe, - .remove = wm8994_remove, - .suspend = wm8994_suspend, - .resume = wm8994_resume, -}; -EXPORT_SYMBOL_GPL(soc_codec_dev_wm8994); - /** * wm8994_mic_detect - Enable microphone detection via the WM8994 IRQ * @@ -3811,7 +3754,7 @@ EXPORT_SYMBOL_GPL(wm8994_mic_detect); static irqreturn_t wm8994_mic_irq(int irq, void *data) { struct wm8994_priv *priv = data; - struct snd_soc_codec *codec = &priv->codec; + struct snd_soc_codec *codec = priv->codec; int reg; int report;
@@ -3843,47 +3786,20 @@ static irqreturn_t wm8994_mic_irq(int irq, void *data) return IRQ_HANDLED; }
-static int wm8994_codec_probe(struct platform_device *pdev) +static int wm8994_codec_probe(struct snd_soc_codec *codec) { - int ret; struct wm8994_priv *wm8994; - struct snd_soc_codec *codec; - int i; - u16 rev; + int ret, i, rev;
- if (wm8994_codec) { - dev_err(&pdev->dev, "Another WM8994 is registered\n"); - return -EINVAL; - } + codec->control_data = dev_get_drvdata(codec->dev->parent);
wm8994 = kzalloc(sizeof(struct wm8994_priv), GFP_KERNEL); - if (!wm8994) { - dev_err(&pdev->dev, "Failed to allocate private data\n"); + if (wm8994 == NULL) return -ENOMEM; - } - - codec = &wm8994->codec; - - mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - snd_soc_codec_set_drvdata(codec, wm8994); - codec->control_data = dev_get_drvdata(pdev->dev.parent); - codec->name = "WM8994"; - codec->owner = THIS_MODULE; - codec->read = wm8994_read; - codec->write = wm8994_write; - codec->readable_register = wm8994_readable; - codec->bias_level = SND_SOC_BIAS_OFF; - codec->set_bias_level = wm8994_set_bias_level; - codec->dai = &wm8994_dai[0]; - codec->num_dai = 3; - codec->reg_cache_size = WM8994_MAX_REGISTER; - codec->reg_cache = &wm8994->reg_cache; - codec->dev = &pdev->dev; - - wm8994->pdata = pdev->dev.parent->platform_data; + + wm8994->pdata = dev_get_platdata(codec->dev->parent); + wm8994->codec = codec;
/* Fill the cache with physical values we inherited; don't reset */ ret = wm8994_bulk_read(codec->control_data, 0, @@ -3919,25 +3835,25 @@ static int wm8994_codec_probe(struct platform_device *pdev) ret = wm8994_request_irq(codec->control_data, WM8994_IRQ_MIC1_DET, wm8994_mic_irq, "Mic 1 detect", wm8994); if (ret != 0) - dev_warn(&pdev->dev, + dev_warn(codec->dev, "Failed to request Mic1 detect IRQ: %d\n", ret);
ret = wm8994_request_irq(codec->control_data, WM8994_IRQ_MIC1_SHRT, wm8994_mic_irq, "Mic 1 short", wm8994); if (ret != 0) - dev_warn(&pdev->dev, + dev_warn(codec->dev, "Failed to request Mic1 short IRQ: %d\n", ret);
ret = wm8994_request_irq(codec->control_data, WM8994_IRQ_MIC2_DET, wm8994_mic_irq, "Mic 2 detect", wm8994); if (ret != 0) - dev_warn(&pdev->dev, + dev_warn(codec->dev, "Failed to request Mic2 detect IRQ: %d\n", ret);
ret = wm8994_request_irq(codec->control_data, WM8994_IRQ_MIC2_SHRT, wm8994_mic_irq, "Mic 2 short", wm8994); if (ret != 0) - dev_warn(&pdev->dev, + dev_warn(codec->dev, "Failed to request Mic2 short IRQ: %d\n", ret);
/* Remember if AIFnLRCLK is configured as a GPIO. This should be @@ -3968,13 +3884,8 @@ static int wm8994_codec_probe(struct platform_device *pdev) wm8994->lrclk_shared[1] = 0; }
- for (i = 0; i < ARRAY_SIZE(wm8994_dai); i++) - wm8994_dai[i].dev = codec->dev; - wm8994_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
- wm8994_codec = codec; - /* Latch volume updates (right only; we always do left then right). */ snd_soc_update_bits(codec, WM8994_AIF1_DAC1_RIGHT_VOLUME, WM8994_AIF1DAC1_VU, WM8994_AIF1DAC1_VU); @@ -4006,24 +3917,18 @@ static int wm8994_codec_probe(struct platform_device *pdev)
wm8994_update_class_w(codec);
- ret = snd_soc_register_codec(codec); - if (ret != 0) { - dev_err(codec->dev, "Failed to register codec: %d\n", ret); - goto err_irq; - } + wm8994_handle_pdata(wm8994);
- ret = snd_soc_register_dais(wm8994_dai, ARRAY_SIZE(wm8994_dai)); - if (ret != 0) { - dev_err(codec->dev, "Failed to register DAIs: %d\n", ret); - goto err_codec; - } - - platform_set_drvdata(pdev, wm8994); + wm_hubs_add_analogue_controls(codec); + snd_soc_add_controls(codec, wm8994_snd_controls, + ARRAY_SIZE(wm8994_snd_controls)); + snd_soc_dapm_new_controls(codec, wm8994_dapm_widgets, + ARRAY_SIZE(wm8994_dapm_widgets)); + wm_hubs_add_analogue_routes(codec, 0, 0); + snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon));
return 0;
-err_codec: - snd_soc_unregister_codec(codec); err_irq: wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_SHRT, wm8994); wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_DET, wm8994); @@ -4034,31 +3939,53 @@ err: return ret; }
-static int __devexit wm8994_codec_remove(struct platform_device *pdev) +static int wm8994_codec_remove(struct snd_soc_codec *codec) { - struct wm8994_priv *wm8994 = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = &wm8994->codec; + struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF); - snd_soc_unregister_dais(wm8994_dai, ARRAY_SIZE(wm8994_dai)); - snd_soc_unregister_codec(&wm8994->codec); + wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_SHRT, wm8994); wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_DET, wm8994); wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_SHRT, wm8994); wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_DET, wm8994); kfree(wm8994); - wm8994_codec = NULL;
return 0; }
+struct snd_soc_codec_driver soc_codec_dev_wm8994 = { + .name = "wm8994", + .owner = THIS_MODULE, + .probe = wm8994_codec_probe, + .remove = wm8994_codec_remove, + .suspend = wm8994_suspend, + .resume = wm8994_resume, + .read = wm8994_read, + .write = wm8994_write, + .set_bias_level = wm8994_set_bias_level, +}; +EXPORT_SYMBOL_GPL(soc_codec_dev_wm8994); + +static int __devinit wm8994_probe(struct platform_device *pdev) +{ + return snd_soc_register_codec(&pdev->dev, pdev->id, &soc_codec_dev_wm8994, + wm8994_dai, ARRAY_SIZE(wm8994_dai)); +} + +static int __devexit wm8994_remove(struct platform_device *pdev) +{ + snd_soc_unregister_codec(&pdev->dev, pdev->id); + return 0; +} + static struct platform_driver wm8994_codec_driver = { .driver = { .name = "wm8994-codec", .owner = THIS_MODULE, }, - .probe = wm8994_codec_probe, - .remove = __devexit_p(wm8994_codec_remove), + .probe = wm8994_probe, + .remove = __devexit_p(wm8994_remove), };
static __init int wm8994_init(void) diff --git a/sound/soc/codecs/wm8994.h b/sound/soc/codecs/wm8994.h index 7072dc5..446ecf1 100644 --- a/sound/soc/codecs/wm8994.h +++ b/sound/soc/codecs/wm8994.h @@ -11,8 +11,8 @@
#include <sound/soc.h>
-extern struct snd_soc_codec_device soc_codec_dev_wm8994; -extern struct snd_soc_dai wm8994_dai[]; +extern struct snd_soc_codec_driver soc_codec_dev_wm8994; +extern struct snd_soc_dai_driver wm8994_dai[];
/* Sources for AIF1/2 SYSCLK - use with set_dai_sysclk() */ #define WM8994_SYSCLK_MCLK1 1
Moved Wolfson WM90xx CODECs to multi-component model.
This patch changes the probe() and remove() of the CODEC drivers as follows:-
o Make CODEC driver a platform device (non MFD codecs only) o Moved all struct snd_soc_codec list, mutex, etc initialiasation to core. o Removed all static codec pointers (drivers now support > 1 codec dev) o snd_soc_register_pcms() now done by core. o snd_soc_register_dai() folded into snd_soc_register_codec(). o codec cache can now be malloc()ed by core.
Signed-off-by: Liam Girdwood lrg@slimlogic.co.uk --- sound/soc/codecs/wm9081.c | 205 +++++++++++++-------------------------------- sound/soc/codecs/wm9081.h | 4 +- sound/soc/codecs/wm9090.c | 182 +++++++++++++--------------------------- sound/soc/codecs/wm9090.h | 2 +- 4 files changed, 123 insertions(+), 270 deletions(-)
diff --git a/sound/soc/codecs/wm9081.c b/sound/soc/codecs/wm9081.c index 13186fb..7df7fd6 100644 --- a/sound/soc/codecs/wm9081.c +++ b/sound/soc/codecs/wm9081.c @@ -156,7 +156,8 @@ static struct { };
struct wm9081_priv { - struct snd_soc_codec codec; + enum snd_soc_control_type control_type; + void *control_data; u16 reg_cache[WM9081_MAX_REGISTER + 1]; int sysclk_source; int mclk_rate; @@ -1212,7 +1213,7 @@ static struct snd_soc_dai_ops wm9081_dai_ops = { /* We report two channels because the CODEC processes a stereo signal, even * though it is only capable of handling a mono output. */ -struct snd_soc_dai wm9081_dai = { +struct snd_soc_dai_driver wm9081_dai = { .name = "WM9081", .playback = { .stream_name = "HiFi Playback", @@ -1225,32 +1226,41 @@ struct snd_soc_dai wm9081_dai = { }; EXPORT_SYMBOL_GPL(wm9081_dai);
- -static struct snd_soc_codec *wm9081_codec; - -static int wm9081_probe(struct platform_device *pdev) +static int wm9081_probe(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - struct wm9081_priv *wm9081; - int ret = 0; + struct wm9081_priv *wm9081 = snd_soc_codec_get_drvdata(codec); + int ret; + u16 reg;
- if (wm9081_codec == NULL) { - dev_err(&pdev->dev, "Codec device not registered\n"); - return -ENODEV; + codec->control_data = wm9081->control_data; + ret = snd_soc_codec_set_cache_io(codec, 8, 16, wm9081->control_type); + if (ret != 0) { + dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); + return ret; }
- socdev->card->codec = wm9081_codec; - codec = wm9081_codec; - wm9081 = snd_soc_codec_get_drvdata(codec); + reg = snd_soc_read(codec, WM9081_SOFTWARE_RESET); + if (reg != 0x9081) { + dev_err(codec->dev, "Device is not a WM9081: ID=0x%x\n", reg); + ret = -EINVAL; + return ret; + }
- /* register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); + ret = wm9081_reset(codec); if (ret < 0) { - dev_err(codec->dev, "failed to create pcms: %d\n", ret); - goto pcm_err; + dev_err(codec->dev, "Failed to issue reset\n"); + return ret; }
+ wm9081_set_bias_level(codec, SND_SOC_BIAS_STANDBY); + + /* Enable zero cross by default */ + reg = snd_soc_read(codec, WM9081_ANALOGUE_LINEOUT); + snd_soc_write(codec, WM9081_ANALOGUE_LINEOUT, reg | WM9081_LINEOUTZC); + reg = snd_soc_read(codec, WM9081_ANALOGUE_SPEAKER_PGA); + snd_soc_write(codec, WM9081_ANALOGUE_SPEAKER_PGA, + reg | WM9081_SPKPGAZC); + snd_soc_add_controls(codec, wm9081_snd_controls, ARRAY_SIZE(wm9081_snd_controls)); if (!wm9081->retune) { @@ -1265,40 +1275,28 @@ static int wm9081_probe(struct platform_device *pdev) snd_soc_dapm_add_routes(codec, audio_paths, ARRAY_SIZE(audio_paths));
return ret; - -pcm_err: - return ret; }
-static int wm9081_remove(struct platform_device *pdev) +static int wm9081_remove(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - - snd_soc_free_pcms(socdev); - snd_soc_dapm_free(socdev); - + wm9081_set_bias_level(codec, SND_SOC_BIAS_OFF); return 0; }
#ifdef CONFIG_PM -static int wm9081_suspend(struct platform_device *pdev, pm_message_t state) +static int wm9081_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; - wm9081_set_bias_level(codec, SND_SOC_BIAS_OFF);
return 0; }
-static int wm9081_resume(struct platform_device *pdev) +static int wm9081_resume(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; u16 *reg_cache = codec->reg_cache; int i;
- for (i = 0; i < codec->reg_cache_size; i++) { + for (i = 0; i < codec->driver->reg_cache_size; i++) { if (i == WM9081_SOFTWARE_RESET) continue;
@@ -1314,132 +1312,46 @@ static int wm9081_resume(struct platform_device *pdev) #define wm9081_resume NULL #endif
-struct snd_soc_codec_device soc_codec_dev_wm9081 = { +struct snd_soc_codec_driver soc_codec_dev_wm9081 = { + .name = "wm9081", + .owner = THIS_MODULE, .probe = wm9081_probe, .remove = wm9081_remove, - .suspend = wm9081_suspend, + .suspend = wm9081_suspend, .resume = wm9081_resume, + .set_bias_level = wm9081_set_bias_level, + .reg_cache_size = sizeof(wm9081_reg_defaults), + .reg_word_size = sizeof(u16), + .reg_cache_default = wm9081_reg_defaults, + .volatile_register = wm9081_volatile_register, }; EXPORT_SYMBOL_GPL(soc_codec_dev_wm9081);
-static int wm9081_register(struct wm9081_priv *wm9081, - enum snd_soc_control_type control) -{ - struct snd_soc_codec *codec = &wm9081->codec; - int ret; - u16 reg; - - if (wm9081_codec) { - dev_err(codec->dev, "Another WM9081 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, wm9081); - codec->name = "WM9081"; - codec->owner = THIS_MODULE; - codec->dai = &wm9081_dai; - codec->num_dai = 1; - codec->reg_cache_size = ARRAY_SIZE(wm9081->reg_cache); - codec->reg_cache = &wm9081->reg_cache; - codec->bias_level = SND_SOC_BIAS_OFF; - codec->set_bias_level = wm9081_set_bias_level; - codec->volatile_register = wm9081_volatile_register; - - memcpy(codec->reg_cache, wm9081_reg_defaults, - sizeof(wm9081_reg_defaults)); - - ret = snd_soc_codec_set_cache_io(codec, 8, 16, control); - if (ret != 0) { - dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); - return ret; - } - - reg = snd_soc_read(codec, WM9081_SOFTWARE_RESET); - if (reg != 0x9081) { - dev_err(codec->dev, "Device is not a WM9081: ID=0x%x\n", reg); - ret = -EINVAL; - goto err; - } - - ret = wm9081_reset(codec); - if (ret < 0) { - dev_err(codec->dev, "Failed to issue reset\n"); - return ret; - } - - wm9081_set_bias_level(codec, SND_SOC_BIAS_STANDBY); - - /* Enable zero cross by default */ - reg = snd_soc_read(codec, WM9081_ANALOGUE_LINEOUT); - snd_soc_write(codec, WM9081_ANALOGUE_LINEOUT, reg | WM9081_LINEOUTZC); - reg = snd_soc_read(codec, WM9081_ANALOGUE_SPEAKER_PGA); - snd_soc_write(codec, WM9081_ANALOGUE_SPEAKER_PGA, - reg | WM9081_SPKPGAZC); - - wm9081_dai.dev = codec->dev; - - wm9081_codec = codec; - - ret = snd_soc_register_codec(codec); - if (ret != 0) { - dev_err(codec->dev, "Failed to register codec: %d\n", ret); - return ret; - } - - ret = snd_soc_register_dai(&wm9081_dai); - if (ret != 0) { - dev_err(codec->dev, "Failed to register DAI: %d\n", ret); - snd_soc_unregister_codec(codec); - return ret; - } - - return 0; - -err: - kfree(wm9081); - return ret; -} - -static void wm9081_unregister(struct wm9081_priv *wm9081) -{ - wm9081_set_bias_level(&wm9081->codec, SND_SOC_BIAS_OFF); - snd_soc_unregister_dai(&wm9081_dai); - snd_soc_unregister_codec(&wm9081->codec); - kfree(wm9081); - wm9081_codec = NULL; -} - +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) static __devinit int wm9081_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct wm9081_priv *wm9081; - struct snd_soc_codec *codec; + int ret;
wm9081 = kzalloc(sizeof(struct wm9081_priv), GFP_KERNEL); if (wm9081 == NULL) return -ENOMEM;
- codec = &wm9081->codec; - codec->hw_write = (hw_write_t)i2c_master_send; - wm9081->retune = i2c->dev.platform_data; - i2c_set_clientdata(i2c, wm9081); - codec->control_data = i2c; + wm9081->control_data = i2c;
- codec->dev = &i2c->dev; - - return wm9081_register(wm9081, SND_SOC_I2C); + ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &soc_codec_dev_wm9081, &wm9081_dai, 1); + if (ret < 0) + kfree(wm9081); + return ret; }
static __devexit int wm9081_i2c_remove(struct i2c_client *client) { - struct wm9081_priv *wm9081 = i2c_get_clientdata(client); - wm9081_unregister(wm9081); + snd_soc_unregister_codec(&client->dev, client->addr); + kfree(i2c_get_clientdata(client)); return 0; }
@@ -1458,24 +1370,27 @@ static struct i2c_driver wm9081_i2c_driver = { .remove = __devexit_p(wm9081_i2c_remove), .id_table = wm9081_i2c_id, }; +#endif
static int __init wm9081_modinit(void) { - int ret; - + int ret = 0; +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) ret = i2c_add_driver(&wm9081_i2c_driver); if (ret != 0) { printk(KERN_ERR "Failed to register WM9081 I2C driver: %d\n", ret); } - +#endif return ret; } module_init(wm9081_modinit);
static void __exit wm9081_exit(void) { +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) i2c_del_driver(&wm9081_i2c_driver); +#endif } module_exit(wm9081_exit);
diff --git a/sound/soc/codecs/wm9081.h b/sound/soc/codecs/wm9081.h index 42d3bc7..bb4a78b 100644 --- a/sound/soc/codecs/wm9081.h +++ b/sound/soc/codecs/wm9081.h @@ -15,8 +15,8 @@
#include <sound/soc.h>
-extern struct snd_soc_dai wm9081_dai; -extern struct snd_soc_codec_device soc_codec_dev_wm9081; +extern struct snd_soc_dai_driver wm9081_dai; +extern struct snd_soc_codec_driver soc_codec_dev_wm9081;
/* * SYSCLK sources diff --git a/sound/soc/codecs/wm9090.c b/sound/soc/codecs/wm9090.c index 1592250..4ced9d3 100644 --- a/sound/soc/codecs/wm9090.c +++ b/sound/soc/codecs/wm9090.c @@ -34,8 +34,6 @@
#include "wm9090.h"
-static struct snd_soc_codec *wm9090_codec; - static const u16 wm9090_reg_defaults[] = { 0x9093, /* R0 - Software Reset */ 0x0006, /* R1 - Power Management (1) */ @@ -142,15 +140,10 @@ static const u16 wm9090_reg_defaults[] = {
/* This struct is used to save the context */ struct wm9090_priv { - /* We're not really registering as a CODEC since ASoC core - * does not yet support multiple CODECs but having the CODEC - * structure means we can reuse some of the ASoC core - * features. - */ - struct snd_soc_codec codec; struct mutex mutex; u16 reg_cache[WM9090_MAX_REGISTER + 1]; struct wm9090_platform_data pdata; + void *control_data; };
static int wm9090_volatile(unsigned int reg) @@ -523,7 +516,7 @@ static int wm9090_set_bias_level(struct snd_soc_codec *codec, case SND_SOC_BIAS_STANDBY: if (codec->bias_level == SND_SOC_BIAS_OFF) { /* Restore the register cache */ - for (i = 1; i < codec->reg_cache_size; i++) { + for (i = 1; i < codec->driver->reg_cache_size; i++) { if (reg_cache[i] == wm9090_reg_defaults[i]) continue; if (wm9090_volatile(i)) @@ -556,51 +549,67 @@ static int wm9090_set_bias_level(struct snd_soc_codec *codec, return 0; }
-static int wm9090_probe(struct platform_device *pdev) +static int wm9090_probe(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - int ret = 0; + struct wm9090_priv *wm9090 = snd_soc_codec_get_drvdata(codec); + int ret;
- if (wm9090_codec == NULL) { - dev_err(&pdev->dev, "Codec device not registered\n"); - return -ENODEV; + codec->control_data = wm9090->control_data; + ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_I2C); + if (ret != 0) { + dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); + return ret; }
- socdev->card->codec = wm9090_codec; - codec = wm9090_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; + ret = snd_soc_read(codec, WM9090_SOFTWARE_RESET); + if (ret < 0) + return ret; + if (ret != wm9090_reg_defaults[WM9090_SOFTWARE_RESET]) { + dev_err(codec->dev, "Device is not a WM9090, ID=%x\n", ret); + return -EINVAL; }
+ ret = snd_soc_write(codec, WM9090_SOFTWARE_RESET, 0); + if (ret < 0) + return ret; + + /* Configure some defaults; they will be written out when we + * bring the bias up. + */ + wm9090->reg_cache[WM9090_IN1_LINE_INPUT_A_VOLUME] |= WM9090_IN1_VU + | WM9090_IN1A_ZC; + wm9090->reg_cache[WM9090_IN1_LINE_INPUT_B_VOLUME] |= WM9090_IN1_VU + | WM9090_IN1B_ZC; + wm9090->reg_cache[WM9090_IN2_LINE_INPUT_A_VOLUME] |= WM9090_IN2_VU + | WM9090_IN2A_ZC; + wm9090->reg_cache[WM9090_IN2_LINE_INPUT_B_VOLUME] |= WM9090_IN2_VU + | WM9090_IN2B_ZC; + wm9090->reg_cache[WM9090_SPEAKER_VOLUME_LEFT] |= + WM9090_SPKOUT_VU | WM9090_SPKOUTL_ZC; + wm9090->reg_cache[WM9090_LEFT_OUTPUT_VOLUME] |= + WM9090_HPOUT1_VU | WM9090_HPOUT1L_ZC; + wm9090->reg_cache[WM9090_RIGHT_OUTPUT_VOLUME] |= + WM9090_HPOUT1_VU | WM9090_HPOUT1R_ZC; + + wm9090->reg_cache[WM9090_CLOCKING_1] |= WM9090_TOCLK_ENA; + + wm9090_set_bias_level(codec, SND_SOC_BIAS_STANDBY); + wm9090_add_controls(codec);
return 0; - -pcm_err: - return ret; }
#ifdef CONFIG_PM -static int wm9090_suspend(struct platform_device *pdev, pm_message_t state) +static int wm9090_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; - wm9090_set_bias_level(codec, SND_SOC_BIAS_OFF);
return 0; }
-static int wm9090_resume(struct platform_device *pdev) +static int wm9090_resume(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - wm9090_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
return 0; @@ -610,21 +619,25 @@ static int wm9090_resume(struct platform_device *pdev) #define wm9090_resume NULL #endif
-static int wm9090_remove(struct platform_device *pdev) +static int wm9090_remove(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - - snd_soc_free_pcms(socdev); - snd_soc_dapm_free(socdev); + wm9090_set_bias_level(codec, SND_SOC_BIAS_OFF);
return 0; }
-struct snd_soc_codec_device soc_codec_dev_wm9090 = { +struct snd_soc_codec_driver soc_codec_dev_wm9090 = { + .name = "WM9090", + .owner = THIS_MODULE, .probe = wm9090_probe, .remove = wm9090_remove, .suspend = wm9090_suspend, .resume = wm9090_resume, + .set_bias_level = wm9090_set_bias_level, + .reg_cache_size = (WM9090_MAX_REGISTER + 1), + .reg_word_size = sizeof(u16), + .reg_cache_default = wm9090_reg_defaults, + .volatile_register = wm9090_volatile, }; EXPORT_SYMBOL_GPL(soc_codec_dev_wm9090);
@@ -632,7 +645,6 @@ static int wm9090_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct wm9090_priv *wm9090; - struct snd_soc_codec *codec; int ret;
wm9090 = kzalloc(sizeof(*wm9090), GFP_KERNEL); @@ -640,102 +652,28 @@ static int wm9090_i2c_probe(struct i2c_client *i2c, dev_err(&i2c->dev, "Can not allocate memory\n"); return -ENOMEM; } - codec = &wm9090->codec;
if (i2c->dev.platform_data) memcpy(&wm9090->pdata, i2c->dev.platform_data, sizeof(wm9090->pdata));
- wm9090_codec = codec; - i2c_set_clientdata(i2c, wm9090); + wm9090->control_data = i2c; + mutex_init(&wm9090->mutex);
- mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - codec->control_data = i2c; - snd_soc_codec_set_drvdata(codec, wm9090); - codec->dev = &i2c->dev; - codec->name = "WM9090"; - codec->owner = THIS_MODULE; - codec->bias_level = SND_SOC_BIAS_OFF; - codec->set_bias_level = wm9090_set_bias_level, - codec->reg_cache_size = WM9090_MAX_REGISTER + 1; - codec->reg_cache = &wm9090->reg_cache; - codec->volatile_register = wm9090_volatile; - - ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_I2C); - if (ret != 0) { - dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); - goto err; - } - - memcpy(&wm9090->reg_cache, wm9090_reg_defaults, - sizeof(wm9090->reg_cache)); - - ret = snd_soc_read(codec, WM9090_SOFTWARE_RESET); - if (ret < 0) - goto err; - if (ret != wm9090_reg_defaults[WM9090_SOFTWARE_RESET]) { - dev_err(&i2c->dev, "Device is not a WM9090, ID=%x\n", ret); - ret = -EINVAL; - goto err; - } - - ret = snd_soc_write(codec, WM9090_SOFTWARE_RESET, 0); + ret = snd_soc_register_codec(&i2c->dev, i2c->addr, + &soc_codec_dev_wm9090, NULL, 0); if (ret < 0) - goto err; - - /* Configure some defaults; they will be written out when we - * bring the bias up. - */ - wm9090->reg_cache[WM9090_IN1_LINE_INPUT_A_VOLUME] |= WM9090_IN1_VU - | WM9090_IN1A_ZC; - wm9090->reg_cache[WM9090_IN1_LINE_INPUT_B_VOLUME] |= WM9090_IN1_VU - | WM9090_IN1B_ZC; - wm9090->reg_cache[WM9090_IN2_LINE_INPUT_A_VOLUME] |= WM9090_IN2_VU - | WM9090_IN2A_ZC; - wm9090->reg_cache[WM9090_IN2_LINE_INPUT_B_VOLUME] |= WM9090_IN2_VU - | WM9090_IN2B_ZC; - wm9090->reg_cache[WM9090_SPEAKER_VOLUME_LEFT] |= - WM9090_SPKOUT_VU | WM9090_SPKOUTL_ZC; - wm9090->reg_cache[WM9090_LEFT_OUTPUT_VOLUME] |= - WM9090_HPOUT1_VU | WM9090_HPOUT1L_ZC; - wm9090->reg_cache[WM9090_RIGHT_OUTPUT_VOLUME] |= - WM9090_HPOUT1_VU | WM9090_HPOUT1R_ZC; - - wm9090->reg_cache[WM9090_CLOCKING_1] |= WM9090_TOCLK_ENA; - - wm9090_set_bias_level(codec, SND_SOC_BIAS_STANDBY); - - ret = snd_soc_register_codec(codec); - if (ret != 0) { - dev_err(&i2c->dev, "Failed to register CODEC: %d\n", ret); - goto err_bias; - } - - return 0; - -err_bias: - wm9090_set_bias_level(codec, SND_SOC_BIAS_OFF); -err: - kfree(wm9090); - i2c_set_clientdata(i2c, NULL); - wm9090_codec = NULL; - + kfree(wm9090); return ret; }
static int wm9090_i2c_remove(struct i2c_client *i2c) { struct wm9090_priv *wm9090 = i2c_get_clientdata(i2c); - struct snd_soc_codec *codec = &wm9090->codec;
- snd_soc_unregister_codec(codec); - wm9090_set_bias_level(codec, SND_SOC_BIAS_OFF); + snd_soc_unregister_codec(&i2c->dev, i2c->addr); kfree(wm9090); - wm9090_codec = NULL;
return 0; } diff --git a/sound/soc/codecs/wm9090.h b/sound/soc/codecs/wm9090.h index b08eab9..bb5c375 100644 --- a/sound/soc/codecs/wm9090.h +++ b/sound/soc/codecs/wm9090.h @@ -23,7 +23,7 @@ #ifndef __WM9090_H #define __WM9090_H
-extern struct snd_soc_codec_device soc_codec_dev_wm9090; +extern struct snd_soc_codec_driver soc_codec_dev_wm9090;
/* * Register values.
Move Wolfson AudioPlus CODECs to multi-component model.
This patch changes the probe() and remove() of the CODEC drivers as follows:-
o Make CODEC driver a platform device (non MFD codecs only) o Moved all struct snd_soc_codec list, mutex, etc initialiasation to core. o Removed all static codec pointers (drivers now support > 1 codec dev) o snd_soc_register_pcms() now done by core. o snd_soc_register_dai() folded into snd_soc_register_codec(). o codec cache can now be malloc()ed by core.
Signed-off-by: Liam Girdwood lrg@slimlogic.co.uk --- sound/soc/codecs/wm8350.c | 231 +++++++++++++++++---------------------------- sound/soc/codecs/wm8350.h | 4 +- sound/soc/codecs/wm8400.c | 181 ++++++++++------------------------- sound/soc/codecs/wm8400.h | 4 +- 4 files changed, 141 insertions(+), 279 deletions(-)
diff --git a/sound/soc/codecs/wm8350.c b/sound/soc/codecs/wm8350.c index 0221ca7..ffb6568 100644 --- a/sound/soc/codecs/wm8350.c +++ b/sound/soc/codecs/wm8350.c @@ -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,75 @@ 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, +}; + +struct snd_soc_dai_driver 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); + +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; + + 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;
- BUG_ON(!wm8350_codec); + 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); @@ -1557,11 +1602,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 +1610,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 +1649,33 @@ 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 = { +struct snd_soc_codec_driver soc_codec_dev_wm8350 = { .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, + .owner = THIS_MODULE, + .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, pdev->id, &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, pdev->id); return 0; }
@@ -1743,8 +1684,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) diff --git a/sound/soc/codecs/wm8350.h b/sound/soc/codecs/wm8350.h index 9ed0467..6dafc20 100644 --- a/sound/soc/codecs/wm8350.h +++ b/sound/soc/codecs/wm8350.h @@ -15,8 +15,8 @@ #include <sound/soc.h> #include <linux/mfd/wm8350/audio.h>
-extern struct snd_soc_dai wm8350_dai; -extern struct snd_soc_codec_device soc_codec_dev_wm8350; +extern struct snd_soc_dai_driver wm8350_dai; +extern struct snd_soc_codec_driver soc_codec_dev_wm8350;
enum wm8350_jack { WM8350_JDL = 1, diff --git a/sound/soc/codecs/wm8400.c b/sound/soc/codecs/wm8400.c index 8f29406..95f7055 100644 --- a/sound/soc/codecs/wm8400.c +++ b/sound/soc/codecs/wm8400.c @@ -65,7 +65,7 @@ static struct regulator_bulk_data power[] = {
/* codec private data */ struct wm8400_priv { - struct snd_soc_codec codec; + struct snd_soc_codec *codec; struct wm8400 *wm8400; u16 fake_register; unsigned int sysclk; @@ -1163,8 +1163,7 @@ static int wm8400_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; u16 audio1 = wm8400_read(codec, WM8400_AUDIO_INTERFACE_1);
audio1 &= ~WM8400_AIF_WL_MASK; @@ -1332,10 +1331,9 @@ static struct snd_soc_dai_ops wm8400_dai_ops = { * 1. ADC/DAC on Primary Interface * 2. ADC on Primary Interface/DAC on secondary */ -struct snd_soc_dai wm8400_dai = { +struct snd_soc_dai_driver wm8400_dai = { /* ADC/DAC on primary */ .name = "WM8400 ADC/DAC Primary", - .id = 1, .playback = { .stream_name = "Playback", .channels_min = 1, @@ -1354,145 +1352,52 @@ struct snd_soc_dai wm8400_dai = { }; EXPORT_SYMBOL_GPL(wm8400_dai);
-static int wm8400_suspend(struct platform_device *pdev, pm_message_t state) +static int wm8400_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; - wm8400_set_bias_level(codec, SND_SOC_BIAS_OFF);
return 0; }
-static int wm8400_resume(struct platform_device *pdev) +static int wm8400_resume(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - wm8400_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
return 0; }
-static struct snd_soc_codec *wm8400_codec; - -static int wm8400_probe(struct platform_device *pdev) -{ - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - int ret; - - if (!wm8400_codec) { - dev_err(&pdev->dev, "wm8400 not yet discovered\n"); - return -ENODEV; - } - codec = wm8400_codec; - - socdev->card->codec = codec; - - /* register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret < 0) { - dev_err(&pdev->dev, "failed to create pcms\n"); - goto pcm_err; - } - - wm8400_add_controls(codec); - wm8400_add_widgets(codec); - -pcm_err: - return ret; -} - -/* power down chip */ -static int wm8400_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_wm8400 = { - .probe = wm8400_probe, - .remove = wm8400_remove, - .suspend = wm8400_suspend, - .resume = wm8400_resume, -}; - static void wm8400_probe_deferred(struct work_struct *work) { struct wm8400_priv *priv = container_of(work, struct wm8400_priv, work); - struct snd_soc_codec *codec = &priv->codec; - int ret; + struct snd_soc_codec *codec = priv->codec;
/* charge output caps */ wm8400_set_bias_level(codec, SND_SOC_BIAS_STANDBY); - - /* We're done, tell the subsystem. */ - ret = snd_soc_register_codec(codec); - if (ret != 0) { - dev_err(priv->wm8400->dev, - "Failed to register codec: %d\n", ret); - goto err; - } - - ret = snd_soc_register_dai(&wm8400_dai); - if (ret != 0) { - dev_err(priv->wm8400->dev, - "Failed to register DAI: %d\n", ret); - goto err_codec; - } - - return; - -err_codec: - snd_soc_unregister_codec(codec); -err: - wm8400_set_bias_level(codec, SND_SOC_BIAS_OFF); }
-static int wm8400_codec_probe(struct platform_device *dev) +static int wm8400_codec_probe(struct snd_soc_codec *codec) { + struct wm8400 *wm8400 = dev_get_platdata(codec->dev); struct wm8400_priv *priv; int ret; u16 reg; - struct snd_soc_codec *codec;
priv = kzalloc(sizeof(struct wm8400_priv), GFP_KERNEL); if (priv == NULL) return -ENOMEM;
- codec = &priv->codec; snd_soc_codec_set_drvdata(codec, priv); - codec->control_data = dev_get_drvdata(&dev->dev); - priv->wm8400 = dev_get_drvdata(&dev->dev); + codec->control_data = priv->wm8400 = wm8400; + priv->codec = codec;
- ret = regulator_bulk_get(priv->wm8400->dev, + ret = regulator_bulk_get(wm8400->dev, ARRAY_SIZE(power), &power[0]); if (ret != 0) { - dev_err(&dev->dev, "Failed to get regulators: %d\n", ret); + dev_err(codec->dev, "Failed to get regulators: %d\n", ret); goto err; }
- codec->dev = &dev->dev; - wm8400_dai.dev = &dev->dev; - - codec->name = "WM8400"; - codec->owner = THIS_MODULE; - codec->read = wm8400_read; - codec->write = wm8400_write; - codec->bias_level = SND_SOC_BIAS_OFF; - codec->set_bias_level = wm8400_set_bias_level; - codec->dai = &wm8400_dai; - codec->num_dai = 1; - codec->reg_cache_size = WM8400_REGISTER_COUNT; - mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); INIT_WORK(&priv->work, wm8400_probe_deferred);
wm8400_codec_reset(codec); @@ -1511,65 +1416,81 @@ static int wm8400_codec_probe(struct platform_device *dev) wm8400_write(codec, WM8400_LEFT_OUTPUT_VOLUME, 0x50 | (1<<8)); wm8400_write(codec, WM8400_RIGHT_OUTPUT_VOLUME, 0x50 | (1<<8));
- wm8400_codec = codec; - if (!schedule_work(&priv->work)) { ret = -EINVAL; goto err_regulator; } - + wm8400_add_controls(codec); + wm8400_add_widgets(codec); return 0;
err_regulator: - wm8400_codec = NULL; regulator_bulk_free(ARRAY_SIZE(power), power); err: kfree(priv); return ret; }
-static int __exit wm8400_codec_remove(struct platform_device *dev) +static int wm8400_codec_remove(struct snd_soc_codec *codec) { - struct wm8400_priv *priv = snd_soc_codec_get_drvdata(wm8400_codec); + struct wm8400_priv *priv = snd_soc_codec_get_drvdata(codec); u16 reg;
- snd_soc_unregister_dai(&wm8400_dai); - snd_soc_unregister_codec(wm8400_codec); - - reg = wm8400_read(wm8400_codec, WM8400_POWER_MANAGEMENT_1); - wm8400_write(wm8400_codec, WM8400_POWER_MANAGEMENT_1, + reg = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1); + wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, reg & (~WM8400_CODEC_ENA));
regulator_bulk_free(ARRAY_SIZE(power), power); kfree(priv);
- wm8400_codec = NULL; + return 0; +} + +struct snd_soc_codec_driver soc_codec_dev_wm8400 = { + .name = "wm8400", + .owner = THIS_MODULE, + .probe = wm8400_codec_probe, + .remove = wm8400_codec_remove, + .suspend = wm8400_suspend, + .resume = wm8400_resume, + .read = wm8400_read, + .write = wm8400_write, + .set_bias_level = wm8400_set_bias_level, +}; +EXPORT_SYMBOL_GPL(soc_codec_dev_wm8400); + +static int __devinit wm8400_probe(struct platform_device *pdev) +{ + return snd_soc_register_codec(&pdev->dev, pdev->id, &soc_codec_dev_wm8400, + &wm8400_dai, 1); +}
+static int __devexit wm8400_remove(struct platform_device *pdev) +{ + snd_soc_unregister_codec(&pdev->dev, pdev->id); return 0; }
static struct platform_driver wm8400_codec_driver = { .driver = { - .name = "wm8400-codec", - .owner = THIS_MODULE, - }, - .probe = wm8400_codec_probe, - .remove = __exit_p(wm8400_codec_remove), + .name = "wm8400-codec", + .owner = THIS_MODULE, + }, + .probe = wm8400_probe, + .remove = __devexit_p(wm8400_remove), };
-static int __init wm8400_codec_init(void) +static __init int wm8400_init(void) { return platform_driver_register(&wm8400_codec_driver); } -module_init(wm8400_codec_init); +module_init(wm8400_init);
-static void __exit wm8400_codec_exit(void) +static __exit void wm8400_exit(void) { platform_driver_unregister(&wm8400_codec_driver); } -module_exit(wm8400_codec_exit); - -EXPORT_SYMBOL_GPL(soc_codec_dev_wm8400); +module_exit(wm8400_exit);
MODULE_DESCRIPTION("ASoC WM8400 driver"); MODULE_AUTHOR("Mark Brown"); diff --git a/sound/soc/codecs/wm8400.h b/sound/soc/codecs/wm8400.h index 79c5934..a75a3ee 100644 --- a/sound/soc/codecs/wm8400.h +++ b/sound/soc/codecs/wm8400.h @@ -56,7 +56,7 @@ #define WM8400_BCLK_DIV_44 (0xE << 1) #define WM8400_BCLK_DIV_48 (0xF << 1)
-extern struct snd_soc_dai wm8400_dai; -extern struct snd_soc_codec_device soc_codec_dev_wm8400; +extern struct snd_soc_dai_driver wm8400_dai; +extern struct snd_soc_codec_driver soc_codec_dev_wm8400;
#endif
Move Wolfson WM97xx AC97 CODECs to multi-component model.
This patch changes the probe() and remove() of the CODEC drivers as follows:-
o Make CODEC driver a platform device (non MFD codecs only) o Moved all struct snd_soc_codec list, mutex, etc initialiasation to core. o Removed all static codec pointers (drivers now support > 1 codec dev) o snd_soc_register_pcms() now done by core. o snd_soc_register_dai() folded into snd_soc_register_codec(). o codec cache can now be malloc()ed by core.
Signed-off-by: Liam Girdwood lrg@slimlogic.co.uk --- sound/soc/codecs/wm9705.c | 114 ++++++++++++++++++----------------------- sound/soc/codecs/wm9705.h | 4 +- sound/soc/codecs/wm9712.c | 122 +++++++++++++++++++------------------------- sound/soc/codecs/wm9712.h | 4 +- sound/soc/codecs/wm9713.c | 125 ++++++++++++++++++++------------------------- sound/soc/codecs/wm9713.h | 4 +- 6 files changed, 166 insertions(+), 207 deletions(-)
diff --git a/sound/soc/codecs/wm9705.c b/sound/soc/codecs/wm9705.c index 8793341..17df388 100644 --- a/sound/soc/codecs/wm9705.c +++ b/sound/soc/codecs/wm9705.c @@ -248,8 +248,7 @@ static int ac97_prepare(struct snd_pcm_substream *substream, { struct snd_pcm_runtime *runtime = substream->runtime; 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; int reg; u16 vra;
@@ -273,7 +272,7 @@ static struct snd_soc_dai_ops wm9705_dai_ops = { .prepare = ac97_prepare, };
-struct snd_soc_dai wm9705_dai[] = { +struct snd_soc_dai_driver wm9705_dai[] = { { .name = "AC97 HiFi", .ac97_control = 1, @@ -318,20 +317,15 @@ static int wm9705_reset(struct snd_soc_codec *codec) }
#ifdef CONFIG_PM -static int wm9705_soc_suspend(struct platform_device *pdev, pm_message_t msg) +static int wm9705_soc_suspend(struct snd_soc_codec *codec, pm_message_t msg) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - soc_ac97_ops.write(codec->ac97, AC97_POWERDOWN, 0xffff);
return 0; }
-static int wm9705_soc_resume(struct platform_device *pdev) +static int wm9705_soc_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, ret; u16 *cache = codec->reg_cache;
@@ -352,49 +346,18 @@ static int wm9705_soc_resume(struct platform_device *pdev) #define wm9705_soc_resume NULL #endif
-static int wm9705_soc_probe(struct platform_device *pdev) +static int wm9705_soc_probe(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; int ret = 0;
printk(KERN_INFO "WM9705 SoC Audio Codec\n");
- socdev->card->codec = kzalloc(sizeof(struct snd_soc_codec), - GFP_KERNEL); - if (socdev->card->codec == NULL) - return -ENOMEM; - codec = socdev->card->codec; - mutex_init(&codec->mutex); - - codec->reg_cache = kmemdup(wm9705_reg, sizeof(wm9705_reg), GFP_KERNEL); - if (codec->reg_cache == NULL) { - ret = -ENOMEM; - goto cache_err; - } - codec->reg_cache_size = sizeof(wm9705_reg); - codec->reg_cache_step = 2; - - codec->name = "WM9705"; - codec->owner = THIS_MODULE; - codec->dai = wm9705_dai; - codec->num_dai = ARRAY_SIZE(wm9705_dai); - codec->write = ac97_write; - codec->read = ac97_read; - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - ret = snd_soc_new_ac97_codec(codec, &soc_ac97_ops, 0); if (ret < 0) { printk(KERN_ERR "wm9705: failed to register AC97 codec\n"); - goto codec_err; + return ret; }
- /* register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret < 0) - goto pcm_err; - ret = wm9705_reset(codec); if (ret) goto reset_err; @@ -406,41 +369,66 @@ static int wm9705_soc_probe(struct platform_device *pdev) return 0;
reset_err: - snd_soc_free_pcms(socdev); -pcm_err: snd_soc_free_ac97_codec(codec); -codec_err: - kfree(codec->reg_cache); -cache_err: - kfree(socdev->card->codec); - socdev->card->codec = NULL; return ret; }
-static int wm9705_soc_remove(struct platform_device *pdev) +static int wm9705_soc_remove(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - - if (codec == NULL) - return 0; - - snd_soc_dapm_free(socdev); - snd_soc_free_pcms(socdev); snd_soc_free_ac97_codec(codec); - kfree(codec->reg_cache); - kfree(codec); return 0; }
-struct snd_soc_codec_device soc_codec_dev_wm9705 = { +struct snd_soc_codec_driver soc_codec_dev_wm9705 = { + .name = "wm9705", + .owner = THIS_MODULE, .probe = wm9705_soc_probe, .remove = wm9705_soc_remove, .suspend = wm9705_soc_suspend, - .resume = wm9705_soc_resume, + .resume = wm9705_soc_resume, + .read = ac97_read, + .write = ac97_write, + .reg_cache_size = sizeof(wm9705_reg), + .reg_word_size = sizeof(u16), + .reg_cache_step = 2, + .reg_cache_default = wm9705_reg, }; EXPORT_SYMBOL_GPL(soc_codec_dev_wm9705);
+static __devinit int wm9705_probe(struct platform_device *pdev) +{ + return snd_soc_register_codec(&pdev->dev, pdev->id, + &soc_codec_dev_wm9705, wm9705_dai, ARRAY_SIZE(wm9705_dai)); +} + +static int __devexit wm9705_remove(struct platform_device *pdev) +{ + snd_soc_unregister_codec(&pdev->dev, pdev->id); + return 0; +} + +static struct platform_driver wm9705_codec_driver = { + .driver = { + .name = "wm9705-codec", + .owner = THIS_MODULE, + }, + + .probe = wm9705_probe, + .remove = __devexit_p(wm9705_remove), +}; + +static int __init wm9705_init(void) +{ + return platform_driver_register(&wm9705_codec_driver); +} +module_init(wm9705_init); + +static void __exit wm9705_exit(void) +{ + platform_driver_unregister(&wm9705_codec_driver); +} +module_exit(wm9705_exit); + MODULE_DESCRIPTION("ASoC WM9705 driver"); MODULE_AUTHOR("Ian Molton"); MODULE_LICENSE("GPL v2"); diff --git a/sound/soc/codecs/wm9705.h b/sound/soc/codecs/wm9705.h index d380f11..189249e 100644 --- a/sound/soc/codecs/wm9705.h +++ b/sound/soc/codecs/wm9705.h @@ -8,7 +8,7 @@ #define WM9705_DAI_AC97_HIFI 0 #define WM9705_DAI_AC97_AUX 1
-extern struct snd_soc_dai wm9705_dai[2]; -extern struct snd_soc_codec_device soc_codec_dev_wm9705; +extern struct snd_soc_dai_driver wm9705_dai[2]; +extern struct snd_soc_codec_driver soc_codec_dev_wm9705;
#endif diff --git a/sound/soc/codecs/wm9712.c b/sound/soc/codecs/wm9712.c index 28790a2..2adb9d8 100644 --- a/sound/soc/codecs/wm9712.c +++ b/sound/soc/codecs/wm9712.c @@ -478,8 +478,7 @@ static int ac97_prepare(struct snd_pcm_substream *substream, { struct snd_pcm_runtime *runtime = substream->runtime; 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; int reg; u16 vra;
@@ -499,8 +498,7 @@ static int ac97_aux_prepare(struct snd_pcm_substream *substream, { struct snd_pcm_runtime *runtime = substream->runtime; 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; u16 vra, xsle;
vra = ac97_read(codec, AC97_EXTENDED_STATUS); @@ -526,7 +524,7 @@ static struct snd_soc_dai_ops wm9712_dai_ops_aux = { .prepare = ac97_aux_prepare, };
-struct snd_soc_dai wm9712_dai[] = { +struct snd_soc_dai_driver wm9712_dai[] = { { .name = "AC97 HiFi", .ac97_control = 1, @@ -597,20 +595,15 @@ err: return -EIO; }
-static int wm9712_soc_suspend(struct platform_device *pdev, +static int wm9712_soc_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; - wm9712_set_bias_level(codec, SND_SOC_BIAS_OFF); return 0; }
-static int wm9712_soc_resume(struct platform_device *pdev) +static int wm9712_soc_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, ret; u16 *cache = codec->reg_cache;
@@ -635,51 +628,18 @@ static int wm9712_soc_resume(struct platform_device *pdev) return ret; }
-static int wm9712_soc_probe(struct platform_device *pdev) +static int wm9712_soc_probe(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; int ret = 0;
printk(KERN_INFO "WM9711/WM9712 SoC Audio Codec %s\n", WM9712_VERSION);
- socdev->card->codec = kzalloc(sizeof(struct snd_soc_codec), - GFP_KERNEL); - if (socdev->card->codec == NULL) - return -ENOMEM; - codec = socdev->card->codec; - mutex_init(&codec->mutex); - - codec->reg_cache = kmemdup(wm9712_reg, sizeof(wm9712_reg), GFP_KERNEL); - - if (codec->reg_cache == NULL) { - ret = -ENOMEM; - goto cache_err; - } - codec->reg_cache_size = sizeof(wm9712_reg); - codec->reg_cache_step = 2; - - codec->name = "WM9712"; - codec->owner = THIS_MODULE; - codec->dai = wm9712_dai; - codec->num_dai = ARRAY_SIZE(wm9712_dai); - codec->write = ac97_write; - codec->read = ac97_read; - codec->set_bias_level = wm9712_set_bias_level; - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - ret = snd_soc_new_ac97_codec(codec, &soc_ac97_ops, 0); if (ret < 0) { printk(KERN_ERR "wm9712: failed to register AC97 codec\n"); - goto codec_err; + return ret; }
- /* register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret < 0) - goto pcm_err; - ret = wm9712_reset(codec, 0); if (ret < 0) { printk(KERN_ERR "Failed to reset WM9712: AC97 link error\n"); @@ -697,43 +657,67 @@ static int wm9712_soc_probe(struct platform_device *pdev) return 0;
reset_err: - snd_soc_free_pcms(socdev); -pcm_err: snd_soc_free_ac97_codec(codec); - -codec_err: - kfree(codec->reg_cache); - -cache_err: - kfree(socdev->card->codec); - socdev->card->codec = NULL; return ret; }
-static int wm9712_soc_remove(struct platform_device *pdev) +static int wm9712_soc_remove(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - - if (codec == NULL) - return 0; - - snd_soc_dapm_free(socdev); - snd_soc_free_pcms(socdev); snd_soc_free_ac97_codec(codec); - kfree(codec->reg_cache); - kfree(codec); return 0; }
-struct snd_soc_codec_device soc_codec_dev_wm9712 = { +struct snd_soc_codec_driver soc_codec_dev_wm9712 = { + .name = "wm9712", + .owner = THIS_MODULE, .probe = wm9712_soc_probe, .remove = wm9712_soc_remove, .suspend = wm9712_soc_suspend, - .resume = wm9712_soc_resume, + .resume = wm9712_soc_resume, + .read = ac97_read, + .write = ac97_write, + .set_bias_level = wm9712_set_bias_level, + .reg_cache_size = sizeof(wm9712_reg), + .reg_word_size = sizeof(u16), + .reg_cache_step = 2, + .reg_cache_default = wm9712_reg, }; EXPORT_SYMBOL_GPL(soc_codec_dev_wm9712);
+static __devinit int wm9712_probe(struct platform_device *pdev) +{ + return snd_soc_register_codec(&pdev->dev, pdev->id, + &soc_codec_dev_wm9712, wm9712_dai, ARRAY_SIZE(wm9712_dai)); +} + +static int __devexit wm9712_remove(struct platform_device *pdev) +{ + snd_soc_unregister_codec(&pdev->dev, pdev->id); + return 0; +} + +static struct platform_driver wm9712_codec_driver = { + .driver = { + .name = "wm9712-codec", + .owner = THIS_MODULE, + }, + + .probe = wm9712_probe, + .remove = __devexit_p(wm9712_remove), +}; + +static int __init wm9712_init(void) +{ + return platform_driver_register(&wm9712_codec_driver); +} +module_init(wm9712_init); + +static void __exit wm9712_exit(void) +{ + platform_driver_unregister(&wm9712_codec_driver); +} +module_exit(wm9712_exit); + MODULE_DESCRIPTION("ASoC WM9711/WM9712 driver"); MODULE_AUTHOR("Liam Girdwood"); MODULE_LICENSE("GPL"); diff --git a/sound/soc/codecs/wm9712.h b/sound/soc/codecs/wm9712.h index d29e8a1..a275bf7 100644 --- a/sound/soc/codecs/wm9712.h +++ b/sound/soc/codecs/wm9712.h @@ -8,7 +8,7 @@ #define WM9712_DAI_AC97_HIFI 0 #define WM9712_DAI_AC97_AUX 1
-extern struct snd_soc_dai wm9712_dai[2]; -extern struct snd_soc_codec_device soc_codec_dev_wm9712; +extern struct snd_soc_dai_driver wm9712_dai[2]; +extern struct snd_soc_codec_driver soc_codec_dev_wm9712;
#endif diff --git a/sound/soc/codecs/wm9713.c b/sound/soc/codecs/wm9713.c index 34e0c91..44c6a9a 100644 --- a/sound/soc/codecs/wm9713.c +++ b/sound/soc/codecs/wm9713.c @@ -1057,7 +1057,7 @@ static struct snd_soc_dai_ops wm9713_dai_ops_voice = { .set_tristate = wm9713_set_dai_tristate, };
-struct snd_soc_dai wm9713_dai[] = { +struct snd_soc_dai_driver wm9713_dai[] = { { .name = "AC97 HiFi", .ac97_control = 1, @@ -1152,11 +1152,9 @@ static int wm9713_set_bias_level(struct snd_soc_codec *codec, return 0; }
-static int wm9713_soc_suspend(struct platform_device *pdev, +static int wm9713_soc_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; u16 reg;
/* Disable everything except touchpanel - that will be handled @@ -1171,10 +1169,8 @@ static int wm9713_soc_suspend(struct platform_device *pdev, return 0; }
-static int wm9713_soc_resume(struct platform_device *pdev) +static int wm9713_soc_resume(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec); int i, ret; u16 *cache = codec->reg_cache; @@ -1204,53 +1200,20 @@ static int wm9713_soc_resume(struct platform_device *pdev) return ret; }
-static int wm9713_soc_probe(struct platform_device *pdev) +static int wm9713_soc_probe(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; + struct wm9713_priv *wm9713; int ret = 0, reg;
- socdev->card->codec = kzalloc(sizeof(struct snd_soc_codec), - GFP_KERNEL); - if (socdev->card->codec == NULL) + wm9713 = kzalloc(sizeof(struct wm9713_priv), GFP_KERNEL); + if (wm9713 == NULL) return -ENOMEM; - codec = socdev->card->codec; - mutex_init(&codec->mutex); - - codec->reg_cache = kmemdup(wm9713_reg, sizeof(wm9713_reg), GFP_KERNEL); - if (codec->reg_cache == NULL) { - ret = -ENOMEM; - goto cache_err; - } - codec->reg_cache_size = sizeof(wm9713_reg); - codec->reg_cache_step = 2; - - snd_soc_codec_set_drvdata(codec, kzalloc(sizeof(struct wm9713_priv), - GFP_KERNEL)); - if (snd_soc_codec_get_drvdata(codec) == NULL) { - ret = -ENOMEM; - goto priv_err; - } - - codec->name = "WM9713"; - codec->owner = THIS_MODULE; - codec->dai = wm9713_dai; - codec->num_dai = ARRAY_SIZE(wm9713_dai); - codec->write = ac97_write; - codec->read = ac97_read; - codec->set_bias_level = wm9713_set_bias_level; - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); + snd_soc_codec_set_drvdata(codec, wm9713);
ret = snd_soc_new_ac97_codec(codec, &soc_ac97_ops, 0); if (ret < 0) goto codec_err;
- /* register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret < 0) - goto pcm_err; - /* do a cold reset for the controller and then try * a warm reset followed by an optional cold reset for codec */ wm9713_reset(codec, 0); @@ -1273,47 +1236,71 @@ static int wm9713_soc_probe(struct platform_device *pdev) return 0;
reset_err: - snd_soc_free_pcms(socdev); -pcm_err: snd_soc_free_ac97_codec(codec); - codec_err: - kfree(snd_soc_codec_get_drvdata(codec)); - -priv_err: - kfree(codec->reg_cache); - -cache_err: - kfree(socdev->card->codec); - socdev->card->codec = NULL; + kfree(wm9713); return ret; }
-static int wm9713_soc_remove(struct platform_device *pdev) +static int wm9713_soc_remove(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - - if (codec == NULL) - return 0; - - snd_soc_dapm_free(socdev); - snd_soc_free_pcms(socdev); + struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec); snd_soc_free_ac97_codec(codec); - kfree(snd_soc_codec_get_drvdata(codec)); - kfree(codec->reg_cache); - kfree(codec); + kfree(wm9713); return 0; }
-struct snd_soc_codec_device soc_codec_dev_wm9713 = { +struct snd_soc_codec_driver soc_codec_dev_wm9713 = { + .name = "WM9713", + .owner = THIS_MODULE, .probe = wm9713_soc_probe, .remove = wm9713_soc_remove, .suspend = wm9713_soc_suspend, .resume = wm9713_soc_resume, + .read = ac97_read, + .write = ac97_write, + .set_bias_level = wm9713_set_bias_level, + .reg_cache_size = sizeof(wm9713_reg), + .reg_word_size = sizeof(u16), + .reg_cache_step = 2, + .reg_cache_default = wm9713_reg, }; EXPORT_SYMBOL_GPL(soc_codec_dev_wm9713);
+static __devinit int wm9713_probe(struct platform_device *pdev) +{ + return snd_soc_register_codec(&pdev->dev, pdev->id, + &soc_codec_dev_wm9713, wm9713_dai, ARRAY_SIZE(wm9713_dai)); +} + +static int __devexit wm9713_remove(struct platform_device *pdev) +{ + snd_soc_unregister_codec(&pdev->dev, pdev->id); + return 0; +} + +static struct platform_driver wm9713_codec_driver = { + .driver = { + .name = "wm9713-codec", + .owner = THIS_MODULE, + }, + + .probe = wm9713_probe, + .remove = __devexit_p(wm9713_remove), +}; + +static int __init wm9713_init(void) +{ + return platform_driver_register(&wm9713_codec_driver); +} +module_init(wm9713_init); + +static void __exit wm9713_exit(void) +{ + platform_driver_unregister(&wm9713_codec_driver); +} +module_exit(wm9713_exit); + MODULE_DESCRIPTION("ASoC WM9713/WM9714 driver"); MODULE_AUTHOR("Liam Girdwood"); MODULE_LICENSE("GPL"); diff --git a/sound/soc/codecs/wm9713.h b/sound/soc/codecs/wm9713.h index 63b8d81..0a38180 100644 --- a/sound/soc/codecs/wm9713.h +++ b/sound/soc/codecs/wm9713.h @@ -45,8 +45,8 @@ #define WM9713_DAI_AC97_AUX 1 #define WM9713_DAI_PCM_VOICE 2
-extern struct snd_soc_codec_device soc_codec_dev_wm9713; -extern struct snd_soc_dai wm9713_dai[3]; +extern struct snd_soc_codec_driver soc_codec_dev_wm9713; +extern struct snd_soc_dai_driver wm9713_dai[3];
int wm9713_reset(struct snd_soc_codec *codec, int try_warm);
participants (5)
-
Bedia, Vaibhav
-
Liam Girdwood
-
Mark Brown
-
peter.ujfalusi@nokia.com
-
Timur Tabi