diff options
author | Liam Girdwood <lrg@slimlogic.co.uk> | 2010-03-17 21:15:21 +0100 |
---|---|---|
committer | Liam Girdwood <lrg@slimlogic.co.uk> | 2010-08-12 15:00:00 +0200 |
commit | f0fba2ad1b6b53d5360125c41953b7afcd6deff0 (patch) | |
tree | f6ad50905f8daa616593c978d7ae992e73241180 /sound/soc/codecs/ad193x.c | |
parent | ASoC: TWL4030: Capture route runtime DAPM ordering fix (diff) | |
download | linux-f0fba2ad1b6b53d5360125c41953b7afcd6deff0.tar.xz linux-f0fba2ad1b6b53d5360125c41953b7afcd6deff0.zip |
ASoC: multi-component - ASoC Multi-Component Support
This patch extends the ASoC API to allow sound cards to have more than one
CODEC and more than one platform DMA controller. This is achieved by dividing
some current ASoC structures that contain both driver data and device data into
structures that only either contain device data or driver data. i.e.
struct snd_soc_codec ---> struct snd_soc_codec (device data)
+-> struct snd_soc_codec_driver (driver data)
struct snd_soc_platform ---> struct snd_soc_platform (device data)
+-> struct snd_soc_platform_driver (driver data)
struct snd_soc_dai ---> struct snd_soc_dai (device data)
+-> struct snd_soc_dai_driver (driver data)
struct snd_soc_device ---> deleted
This now allows ASoC to be more tightly aligned with the Linux driver model and
also means that every ASoC codec, platform and (platform) DAI is a kernel
device. ASoC component private data is now stored as device private data.
The ASoC sound card struct snd_soc_card has also been updated to store lists
of it's components rather than a pointer to a codec and platform. The PCM
runtime struct soc_pcm_runtime now has pointers to all its components.
This patch adds DAPM support for ASoC multi-component and removes struct
snd_soc_socdev from DAPM core. All DAPM calls are now made on a card, codec
or runtime PCM level basis rather than using snd_soc_socdev.
Other notable multi-component changes:-
* Stream operations now de-reference less structures.
* close_delayed work() now runs on a DAI basis rather than looping all DAIs
in a card.
* PM suspend()/resume() operations can now handle N CODECs and Platforms
per sound card.
* Added soc_bind_dai_link() to bind the component devices to the sound card.
* Added soc_dai_link_probe() and soc_dai_link_remove() to probe and remove
DAI link components.
* sysfs entries can now be registered per component per card.
* snd_soc_new_pcms() functionailty rolled into dai_link_probe().
* snd_soc_register_codec() now does all the codec list and mutex init.
This patch changes the probe() and remove() of the CODEC drivers as follows:-
o Make CODEC driver a platform driver
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().
CS4270 portions:
Acked-by: Timur Tabi <timur@freescale.com>
Some TLV320aic23 and Cirrus platform fixes.
Signed-off-by: Ryan Mallon <ryan@bluewatersys.com>
TI CODEC and OMAP fixes
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@nokia.com>
Signed-off-by: Janusz Krzysztofik <jkrzyszt@tis.icnet.pl>
Signed-off-by: Jarkko Nikula <jhnikula@gmail.com>
Samsung platform and misc fixes :-
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Signed-off-by: Joonyoung Shim <jy0922.shim@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Reviewed-by: Jassi Brar <jassi.brar@samsung.com>
Signed-off-by: Seungwhan Youn <sw.youn@samsung.com>
MPC8610 and PPC fixes.
Signed-off-by: Timur Tabi <timur@freescale.com>
i.MX fixes and some core fixes.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
J4740 platform fixes:-
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
CC: Tony Lindgren <tony@atomide.com>
CC: Nicolas Ferre <nicolas.ferre@atmel.com>
CC: Kevin Hilman <khilman@deeprootsystems.com>
CC: Sascha Hauer <s.hauer@pengutronix.de>
CC: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
CC: Kuninori Morimoto <morimoto.kuninori@renesas.com>
CC: Daniel Gloeckner <dg@emlix.com>
CC: Manuel Lauss <mano@roarinelk.homelinux.net>
CC: Mike Frysinger <vapier.adi@gmail.com>
CC: Arnaud Patard <apatard@mandriva.com>
CC: Wan ZongShun <mcuos.com@gmail.com>
Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
Diffstat (limited to 'sound/soc/codecs/ad193x.c')
-rw-r--r-- | sound/soc/codecs/ad193x.c | 217 |
1 files changed, 77 insertions, 140 deletions
diff --git a/sound/soc/codecs/ad193x.c b/sound/soc/codecs/ad193x.c index 1def75e4862f..fa2834c91b9f 100644 --- a/sound/soc/codecs/ad193x.c +++ b/sound/soc/codecs/ad193x.c @@ -24,9 +24,10 @@ /* codec private data */ struct ad193x_priv { - unsigned int sysclk; - struct snd_soc_codec codec; u8 reg_cache[AD193X_NUM_REGS]; + enum snd_soc_control_type bus_type; + void *control_data; + int sysclk; }; /* ad193x register cache & default register settings */ @@ -34,9 +35,6 @@ static const u8 ad193x_reg[AD193X_NUM_REGS] = { 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0, 0, }; -static struct snd_soc_codec *ad193x_codec; -struct snd_soc_codec_device soc_codec_dev_ad193x; - /* * AD193X volume/mute/de-emphasis etc. controls */ @@ -275,8 +273,7 @@ static int ad193x_hw_params(struct snd_pcm_substream *substream, int word_len = 0, reg = 0, master_rate = 0; 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 ad193x_priv *ad193x = snd_soc_codec_get_drvdata(codec); /* bit size */ @@ -323,100 +320,6 @@ static int ad193x_hw_params(struct snd_pcm_substream *substream, return 0; } -static int ad193x_bus_probe(struct device *dev, void *ctrl_data, int bus_type) -{ - struct snd_soc_codec *codec; - struct ad193x_priv *ad193x; - int ret; - - if (ad193x_codec) { - dev_err(dev, "Another ad193x is registered\n"); - return -EINVAL; - } - - ad193x = kzalloc(sizeof(struct ad193x_priv), GFP_KERNEL); - if (ad193x == NULL) - return -ENOMEM; - - dev_set_drvdata(dev, ad193x); - - codec = &ad193x->codec; - mutex_init(&codec->mutex); - codec->control_data = ctrl_data; - codec->dev = dev; - snd_soc_codec_set_drvdata(codec, ad193x); - codec->reg_cache = ad193x->reg_cache; - codec->reg_cache_size = AD193X_NUM_REGS; - codec->name = "AD193X"; - codec->owner = THIS_MODULE; - codec->dai = &ad193x_dai; - codec->num_dai = 1; - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - ad193x_dai.dev = codec->dev; - ad193x_codec = codec; - - memcpy(codec->reg_cache, ad193x_reg, AD193X_NUM_REGS); - - if (bus_type == SND_SOC_I2C) - ret = snd_soc_codec_set_cache_io(codec, 8, 8, bus_type); - else - ret = snd_soc_codec_set_cache_io(codec, 16, 8, bus_type); - if (ret < 0) { - dev_err(codec->dev, "failed to set cache I/O: %d\n", - ret); - kfree(ad193x); - return ret; - } - - /* default setting for ad193x */ - - /* unmute dac channels */ - snd_soc_write(codec, AD193X_DAC_CHNL_MUTE, 0x0); - /* de-emphasis: 48kHz, powedown dac */ - snd_soc_write(codec, AD193X_DAC_CTRL2, 0x1A); - /* powerdown dac, dac in tdm mode */ - snd_soc_write(codec, AD193X_DAC_CTRL0, 0x41); - /* high-pass filter enable */ - snd_soc_write(codec, AD193X_ADC_CTRL0, 0x3); - /* sata delay=1, adc aux mode */ - snd_soc_write(codec, AD193X_ADC_CTRL1, 0x43); - /* pll input: mclki/xi */ - snd_soc_write(codec, AD193X_PLL_CLK_CTRL0, 0x99); /* mclk=24.576Mhz: 0x9D; mclk=12.288Mhz: 0x99 */ - snd_soc_write(codec, AD193X_PLL_CLK_CTRL1, 0x04); - ad193x->sysclk = 12288000; - - ret = snd_soc_register_codec(codec); - if (ret != 0) { - dev_err(codec->dev, "Failed to register codec: %d\n", ret); - kfree(ad193x); - return ret; - } - - ret = snd_soc_register_dai(&ad193x_dai); - if (ret != 0) { - dev_err(codec->dev, "Failed to register DAI: %d\n", ret); - snd_soc_unregister_codec(codec); - kfree(ad193x); - return ret; - } - - return 0; -} - -static int ad193x_bus_remove(struct device *dev) -{ - struct ad193x_priv *ad193x = dev_get_drvdata(dev); - - snd_soc_unregister_dai(&ad193x_dai); - snd_soc_unregister_codec(&ad193x->codec); - kfree(ad193x); - ad193x_codec = NULL; - - return 0; -} - static struct snd_soc_dai_ops ad193x_dai_ops = { .hw_params = ad193x_hw_params, .digital_mute = ad193x_mute, @@ -426,8 +329,8 @@ static struct snd_soc_dai_ops ad193x_dai_ops = { }; /* codec DAI instance */ -struct snd_soc_dai ad193x_dai = { - .name = "AD193X", +static struct snd_soc_dai_driver ad193x_dai = { + .name = "ad193x-hifi", .playback = { .stream_name = "Playback", .channels_min = 2, @@ -446,28 +349,39 @@ struct snd_soc_dai ad193x_dai = { }, .ops = &ad193x_dai_ops, }; -EXPORT_SYMBOL_GPL(ad193x_dai); -static int ad193x_probe(struct platform_device *pdev) +static int ad193x_probe(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - int ret = 0; + struct ad193x_priv *ad193x = snd_soc_codec_get_drvdata(codec); + int ret; - if (ad193x_codec == NULL) { - dev_err(&pdev->dev, "Codec device not registered\n"); - return -ENODEV; + codec->control_data = ad193x->control_data; + if (ad193x->bus_type == SND_SOC_I2C) + ret = snd_soc_codec_set_cache_io(codec, 8, 8, ad193x->bus_type); + else + ret = snd_soc_codec_set_cache_io(codec, 16, 8, ad193x->bus_type); + if (ret < 0) { + dev_err(codec->dev, "failed to set cache I/O: %d\n", + ret); + kfree(ad193x); + return ret; } - socdev->card->codec = ad193x_codec; - codec = ad193x_codec; + /* default setting for ad193x */ - /* 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; - } + /* unmute dac channels */ + snd_soc_write(codec, AD193X_DAC_CHNL_MUTE, 0x0); + /* de-emphasis: 48kHz, powedown dac */ + snd_soc_write(codec, AD193X_DAC_CTRL2, 0x1A); + /* powerdown dac, dac in tdm mode */ + snd_soc_write(codec, AD193X_DAC_CTRL0, 0x41); + /* high-pass filter enable */ + snd_soc_write(codec, AD193X_ADC_CTRL0, 0x3); + /* sata delay=1, adc aux mode */ + snd_soc_write(codec, AD193X_ADC_CTRL1, 0x43); + /* pll input: mclki/xi */ + snd_soc_write(codec, AD193X_PLL_CLK_CTRL0, 0x99); /* mclk=24.576Mhz: 0x9D; mclk=12.288Mhz: 0x99 */ + snd_soc_write(codec, AD193X_PLL_CLK_CTRL1, 0x04); snd_soc_add_controls(codec, ad193x_snd_controls, ARRAY_SIZE(ad193x_snd_controls)); @@ -475,41 +389,47 @@ static int ad193x_probe(struct platform_device *pdev) ARRAY_SIZE(ad193x_dapm_widgets)); snd_soc_dapm_add_routes(codec, audio_paths, ARRAY_SIZE(audio_paths)); -pcm_err: return ret; } -/* power down chip */ -static int ad193x_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_ad193x = { +static struct snd_soc_codec_driver soc_codec_dev_ad193x = { .probe = ad193x_probe, - .remove = ad193x_remove, + .reg_cache_default = ad193x_reg, + .reg_cache_size = AD193X_NUM_REGS, + .reg_word_size = sizeof(u16), }; -EXPORT_SYMBOL_GPL(soc_codec_dev_ad193x); #if defined(CONFIG_SPI_MASTER) static int __devinit ad193x_spi_probe(struct spi_device *spi) { - return ad193x_bus_probe(&spi->dev, spi, SND_SOC_SPI); + struct ad193x_priv *ad193x; + int ret; + + ad193x = kzalloc(sizeof(struct ad193x_priv), GFP_KERNEL); + if (ad193x == NULL) + return -ENOMEM; + + spi_set_drvdata(spi, ad193x); + ad193x->control_data = spi; + ad193x->bus_type = SND_SOC_SPI; + + ret = snd_soc_register_codec(&spi->dev, + &soc_codec_dev_ad193x, &ad193x_dai, 1); + if (ret < 0) + kfree(ad193x); + return ret; } static int __devexit ad193x_spi_remove(struct spi_device *spi) { - return ad193x_bus_remove(&spi->dev); + snd_soc_unregister_codec(&spi->dev); + kfree(spi_get_drvdata(spi)); + return 0; } static struct spi_driver ad193x_spi_driver = { .driver = { - .name = "ad193x", + .name = "ad193x-codec", .owner = THIS_MODULE, }, .probe = ad193x_spi_probe, @@ -528,17 +448,34 @@ MODULE_DEVICE_TABLE(i2c, ad193x_id); static int __devinit ad193x_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { - return ad193x_bus_probe(&client->dev, client, SND_SOC_I2C); + struct ad193x_priv *ad193x; + int ret; + + ad193x = kzalloc(sizeof(struct ad193x_priv), GFP_KERNEL); + if (ad193x == NULL) + return -ENOMEM; + + i2c_set_clientdata(client, ad193x); + ad193x->control_data = client; + ad193x->bus_type = SND_SOC_I2C; + + ret = snd_soc_register_codec(&client->dev, + &soc_codec_dev_ad193x, &ad193x_dai, 1); + if (ret < 0) + kfree(ad193x); + return ret; } static int __devexit ad193x_i2c_remove(struct i2c_client *client) { - return ad193x_bus_remove(&client->dev); + snd_soc_unregister_codec(&client->dev); + kfree(i2c_get_clientdata(client)); + return 0; } static struct i2c_driver ad193x_i2c_driver = { .driver = { - .name = "ad193x", + .name = "ad193x-codec", }, .probe = ad193x_i2c_probe, .remove = __devexit_p(ad193x_i2c_remove), |