aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/wm8974.c
diff options
context:
space:
mode:
authorLiam Girdwood <lrg@slimlogic.co.uk>2010-03-17 16:15:21 -0400
committerLiam Girdwood <lrg@slimlogic.co.uk>2010-08-12 09:00:00 -0400
commitf0fba2ad1b6b53d5360125c41953b7afcd6deff0 (patch)
treef6ad50905f8daa616593c978d7ae992e73241180 /sound/soc/codecs/wm8974.c
parentbda7d2a862e6b788bca2d02d38a07966a9c92e48 (diff)
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/wm8974.c')
-rw-r--r--sound/soc/codecs/wm8974.c171
1 files changed, 47 insertions, 124 deletions
diff --git a/sound/soc/codecs/wm8974.c b/sound/soc/codecs/wm8974.c
index 1468fe10cbbe..52f631c62e29 100644
--- a/sound/soc/codecs/wm8974.c
+++ b/sound/soc/codecs/wm8974.c
@@ -51,12 +51,11 @@ static const u16 wm8974_reg[WM8974_CACHEREGNUM] = {
51#define WM8974_POWER1_BUFIOEN 0x04 51#define WM8974_POWER1_BUFIOEN 0x04
52 52
53struct wm8974_priv { 53struct wm8974_priv {
54 struct snd_soc_codec codec; 54 enum snd_soc_control_type control_type;
55 void *control_data;
55 u16 reg_cache[WM8974_CACHEREGNUM]; 56 u16 reg_cache[WM8974_CACHEREGNUM];
56}; 57};
57 58
58static struct snd_soc_codec *wm8974_codec;
59
60#define wm8974_reset(c) snd_soc_write(c, WM8974_RESET, 0) 59#define wm8974_reset(c) snd_soc_write(c, WM8974_RESET, 0)
61 60
62static const char *wm8974_companding[] = {"Off", "NC", "u-law", "A-law" }; 61static const char *wm8974_companding[] = {"Off", "NC", "u-law", "A-law" };
@@ -566,8 +565,8 @@ static struct snd_soc_dai_ops wm8974_ops = {
566 .set_pll = wm8974_set_dai_pll, 565 .set_pll = wm8974_set_dai_pll,
567}; 566};
568 567
569struct snd_soc_dai wm8974_dai = { 568static struct snd_soc_dai_driver wm8974_dai = {
570 .name = "WM8974 HiFi", 569 .name = "wm8974-hifi",
571 .playback = { 570 .playback = {
572 .stream_name = "Playback", 571 .stream_name = "Playback",
573 .channels_min = 1, 572 .channels_min = 1,
@@ -583,21 +582,15 @@ struct snd_soc_dai wm8974_dai = {
583 .ops = &wm8974_ops, 582 .ops = &wm8974_ops,
584 .symmetric_rates = 1, 583 .symmetric_rates = 1,
585}; 584};
586EXPORT_SYMBOL_GPL(wm8974_dai);
587 585
588static int wm8974_suspend(struct platform_device *pdev, pm_message_t state) 586static int wm8974_suspend(struct snd_soc_codec *codec, pm_message_t state)
589{ 587{
590 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
591 struct snd_soc_codec *codec = socdev->card->codec;
592
593 wm8974_set_bias_level(codec, SND_SOC_BIAS_OFF); 588 wm8974_set_bias_level(codec, SND_SOC_BIAS_OFF);
594 return 0; 589 return 0;
595} 590}
596 591
597static int wm8974_resume(struct platform_device *pdev) 592static int wm8974_resume(struct snd_soc_codec *codec)
598{ 593{
599 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
600 struct snd_soc_codec *codec = socdev->card->codec;
601 int i; 594 int i;
602 u8 data[2]; 595 u8 data[2];
603 u16 *cache = codec->reg_cache; 596 u16 *cache = codec->reg_cache;
@@ -613,156 +606,75 @@ static int wm8974_resume(struct platform_device *pdev)
613 return 0; 606 return 0;
614} 607}
615 608
616static int wm8974_probe(struct platform_device *pdev) 609static int wm8974_probe(struct snd_soc_codec *codec)
617{ 610{
618 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 611 struct wm8974_priv *wm8974 = snd_soc_codec_get_drvdata(codec);
619 struct snd_soc_codec *codec;
620 int ret = 0; 612 int ret = 0;
621 613
622 if (wm8974_codec == NULL) { 614 codec->control_data = wm8974->control_data;
623 dev_err(&pdev->dev, "Codec device not registered\n"); 615 ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_I2C);
624 return -ENODEV; 616 if (ret < 0) {
617 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
618 return ret;
625 } 619 }
626 620
627 socdev->card->codec = wm8974_codec; 621 ret = wm8974_reset(codec);
628 codec = wm8974_codec;
629
630 /* register pcms */
631 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
632 if (ret < 0) { 622 if (ret < 0) {
633 dev_err(codec->dev, "failed to create pcms: %d\n", ret); 623 dev_err(codec->dev, "Failed to issue reset\n");
634 goto pcm_err; 624 return ret;
635 } 625 }
636 626
627 wm8974_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
637 snd_soc_add_controls(codec, wm8974_snd_controls, 628 snd_soc_add_controls(codec, wm8974_snd_controls,
638 ARRAY_SIZE(wm8974_snd_controls)); 629 ARRAY_SIZE(wm8974_snd_controls));
639 wm8974_add_widgets(codec); 630 wm8974_add_widgets(codec);
640 631
641 return ret; 632 return ret;
642
643pcm_err:
644 return ret;
645} 633}
646 634
647/* power down chip */ 635/* power down chip */
648static int wm8974_remove(struct platform_device *pdev) 636static int wm8974_remove(struct snd_soc_codec *codec)
649{ 637{
650 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 638 wm8974_set_bias_level(codec, SND_SOC_BIAS_OFF);
651
652 snd_soc_free_pcms(socdev);
653 snd_soc_dapm_free(socdev);
654
655 return 0; 639 return 0;
656} 640}
657 641
658struct snd_soc_codec_device soc_codec_dev_wm8974 = { 642static struct snd_soc_codec_driver soc_codec_dev_wm8974 = {
659 .probe = wm8974_probe, 643 .probe = wm8974_probe,
660 .remove = wm8974_remove, 644 .remove = wm8974_remove,
661 .suspend = wm8974_suspend, 645 .suspend = wm8974_suspend,
662 .resume = wm8974_resume, 646 .resume = wm8974_resume,
647 .set_bias_level = wm8974_set_bias_level,
648 .reg_cache_size = ARRAY_SIZE(wm8974_reg),
649 .reg_word_size = sizeof(u16),
650 .reg_cache_default = wm8974_reg,
663}; 651};
664EXPORT_SYMBOL_GPL(soc_codec_dev_wm8974);
665
666static __devinit int wm8974_register(struct wm8974_priv *wm8974)
667{
668 int ret;
669 struct snd_soc_codec *codec = &wm8974->codec;
670
671 if (wm8974_codec) {
672 dev_err(codec->dev, "Another WM8974 is registered\n");
673 ret = -EINVAL;
674 goto err;
675 }
676
677 mutex_init(&codec->mutex);
678 INIT_LIST_HEAD(&codec->dapm_widgets);
679 INIT_LIST_HEAD(&codec->dapm_paths);
680
681 snd_soc_codec_set_drvdata(codec, wm8974);
682 codec->name = "WM8974";
683 codec->owner = THIS_MODULE;
684 codec->bias_level = SND_SOC_BIAS_OFF;
685 codec->set_bias_level = wm8974_set_bias_level;
686 codec->dai = &wm8974_dai;
687 codec->num_dai = 1;
688 codec->reg_cache_size = WM8974_CACHEREGNUM;
689 codec->reg_cache = &wm8974->reg_cache;
690
691 ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_I2C);
692 if (ret < 0) {
693 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
694 goto err;
695 }
696
697 memcpy(codec->reg_cache, wm8974_reg, sizeof(wm8974_reg));
698
699 ret = wm8974_reset(codec);
700 if (ret < 0) {
701 dev_err(codec->dev, "Failed to issue reset\n");
702 goto err;
703 }
704
705 wm8974_dai.dev = codec->dev;
706
707 wm8974_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
708
709 wm8974_codec = codec;
710
711 ret = snd_soc_register_codec(codec);
712 if (ret != 0) {
713 dev_err(codec->dev, "Failed to register codec: %d\n", ret);
714 goto err;
715 }
716
717 ret = snd_soc_register_dai(&wm8974_dai);
718 if (ret != 0) {
719 dev_err(codec->dev, "Failed to register DAI: %d\n", ret);
720 goto err_codec;
721 }
722
723 return 0;
724
725err_codec:
726 snd_soc_unregister_codec(codec);
727err:
728 kfree(wm8974);
729 return ret;
730}
731
732static __devexit void wm8974_unregister(struct wm8974_priv *wm8974)
733{
734 wm8974_set_bias_level(&wm8974->codec, SND_SOC_BIAS_OFF);
735 snd_soc_unregister_dai(&wm8974_dai);
736 snd_soc_unregister_codec(&wm8974->codec);
737 kfree(wm8974);
738 wm8974_codec = NULL;
739}
740 652
653#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
741static __devinit int wm8974_i2c_probe(struct i2c_client *i2c, 654static __devinit int wm8974_i2c_probe(struct i2c_client *i2c,
742 const struct i2c_device_id *id) 655 const struct i2c_device_id *id)
743{ 656{
744 struct wm8974_priv *wm8974; 657 struct wm8974_priv *wm8974;
745 struct snd_soc_codec *codec; 658 int ret;
746 659
747 wm8974 = kzalloc(sizeof(struct wm8974_priv), GFP_KERNEL); 660 wm8974 = kzalloc(sizeof(struct wm8974_priv), GFP_KERNEL);
748 if (wm8974 == NULL) 661 if (wm8974 == NULL)
749 return -ENOMEM; 662 return -ENOMEM;
750 663
751 codec = &wm8974->codec;
752 codec->hw_write = (hw_write_t)i2c_master_send;
753
754 i2c_set_clientdata(i2c, wm8974); 664 i2c_set_clientdata(i2c, wm8974);
755 codec->control_data = i2c; 665 wm8974->control_data = i2c;
756
757 codec->dev = &i2c->dev;
758 666
759 return wm8974_register(wm8974); 667 ret = snd_soc_register_codec(&i2c->dev,
668 &soc_codec_dev_wm8974, &wm8974_dai, 1);
669 if (ret < 0)
670 kfree(wm8974);
671 return ret;
760} 672}
761 673
762static __devexit int wm8974_i2c_remove(struct i2c_client *client) 674static __devexit int wm8974_i2c_remove(struct i2c_client *client)
763{ 675{
764 struct wm8974_priv *wm8974 = i2c_get_clientdata(client); 676 snd_soc_unregister_codec(&client->dev);
765 wm8974_unregister(wm8974); 677 kfree(i2c_get_clientdata(client));
766 return 0; 678 return 0;
767} 679}
768 680
@@ -774,23 +686,34 @@ MODULE_DEVICE_TABLE(i2c, wm8974_i2c_id);
774 686
775static struct i2c_driver wm8974_i2c_driver = { 687static struct i2c_driver wm8974_i2c_driver = {
776 .driver = { 688 .driver = {
777 .name = "WM8974", 689 .name = "wm8974-codec",
778 .owner = THIS_MODULE, 690 .owner = THIS_MODULE,
779 }, 691 },
780 .probe = wm8974_i2c_probe, 692 .probe = wm8974_i2c_probe,
781 .remove = __devexit_p(wm8974_i2c_remove), 693 .remove = __devexit_p(wm8974_i2c_remove),
782 .id_table = wm8974_i2c_id, 694 .id_table = wm8974_i2c_id,
783}; 695};
696#endif
784 697
785static int __init wm8974_modinit(void) 698static int __init wm8974_modinit(void)
786{ 699{
787 return i2c_add_driver(&wm8974_i2c_driver); 700 int ret = 0;
701#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
702 ret = i2c_add_driver(&wm8974_i2c_driver);
703 if (ret != 0) {
704 printk(KERN_ERR "Failed to register wm8974 I2C driver: %d\n",
705 ret);
706 }
707#endif
708 return ret;
788} 709}
789module_init(wm8974_modinit); 710module_init(wm8974_modinit);
790 711
791static void __exit wm8974_exit(void) 712static void __exit wm8974_exit(void)
792{ 713{
714#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
793 i2c_del_driver(&wm8974_i2c_driver); 715 i2c_del_driver(&wm8974_i2c_driver);
716#endif
794} 717}
795module_exit(wm8974_exit); 718module_exit(wm8974_exit);
796 719