aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/wm8988.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/codecs/wm8988.c')
-rw-r--r--sound/soc/codecs/wm8988.c261
1 files changed, 85 insertions, 176 deletions
diff --git a/sound/soc/codecs/wm8988.c b/sound/soc/codecs/wm8988.c
index 19ad590ca0b3..d7f259711970 100644
--- a/sound/soc/codecs/wm8988.c
+++ b/sound/soc/codecs/wm8988.c
@@ -52,7 +52,7 @@ static const u16 wm8988_reg[] = {
52/* codec private data */ 52/* codec private data */
53struct wm8988_priv { 53struct wm8988_priv {
54 unsigned int sysclk; 54 unsigned int sysclk;
55 struct snd_soc_codec codec; 55 enum snd_soc_control_type control_type;
56 struct snd_pcm_hw_constraint_list *sysclk_constraints; 56 struct snd_pcm_hw_constraint_list *sysclk_constraints;
57 u16 reg_cache[WM8988_NUM_REG]; 57 u16 reg_cache[WM8988_NUM_REG];
58}; 58};
@@ -608,8 +608,7 @@ static int wm8988_pcm_hw_params(struct snd_pcm_substream *substream,
608 struct snd_soc_dai *dai) 608 struct snd_soc_dai *dai)
609{ 609{
610 struct snd_soc_pcm_runtime *rtd = substream->private_data; 610 struct snd_soc_pcm_runtime *rtd = substream->private_data;
611 struct snd_soc_device *socdev = rtd->socdev; 611 struct snd_soc_codec *codec = rtd->codec;
612 struct snd_soc_codec *codec = socdev->card->codec;
613 struct wm8988_priv *wm8988 = snd_soc_codec_get_drvdata(codec); 612 struct wm8988_priv *wm8988 = snd_soc_codec_get_drvdata(codec);
614 u16 iface = snd_soc_read(codec, WM8988_IFACE) & 0x1f3; 613 u16 iface = snd_soc_read(codec, WM8988_IFACE) & 0x1f3;
615 u16 srate = snd_soc_read(codec, WM8988_SRATE) & 0x180; 614 u16 srate = snd_soc_read(codec, WM8988_SRATE) & 0x180;
@@ -711,8 +710,8 @@ static struct snd_soc_dai_ops wm8988_ops = {
711 .digital_mute = wm8988_mute, 710 .digital_mute = wm8988_mute,
712}; 711};
713 712
714struct snd_soc_dai wm8988_dai = { 713static struct snd_soc_dai_driver wm8988_dai = {
715 .name = "WM8988", 714 .name = "wm8988-hifi",
716 .playback = { 715 .playback = {
717 .stream_name = "Playback", 716 .stream_name = "Playback",
718 .channels_min = 1, 717 .channels_min = 1,
@@ -730,21 +729,15 @@ struct snd_soc_dai wm8988_dai = {
730 .ops = &wm8988_ops, 729 .ops = &wm8988_ops,
731 .symmetric_rates = 1, 730 .symmetric_rates = 1,
732}; 731};
733EXPORT_SYMBOL_GPL(wm8988_dai);
734 732
735static int wm8988_suspend(struct platform_device *pdev, pm_message_t state) 733static int wm8988_suspend(struct snd_soc_codec *codec, pm_message_t state)
736{ 734{
737 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
738 struct snd_soc_codec *codec = socdev->card->codec;
739
740 wm8988_set_bias_level(codec, SND_SOC_BIAS_OFF); 735 wm8988_set_bias_level(codec, SND_SOC_BIAS_OFF);
741 return 0; 736 return 0;
742} 737}
743 738
744static int wm8988_resume(struct platform_device *pdev) 739static int wm8988_resume(struct snd_soc_codec *codec)
745{ 740{
746 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
747 struct snd_soc_codec *codec = socdev->card->codec;
748 int i; 741 int i;
749 u8 data[2]; 742 u8 data[2];
750 u16 *cache = codec->reg_cache; 743 u16 *cache = codec->reg_cache;
@@ -763,99 +756,22 @@ static int wm8988_resume(struct platform_device *pdev)
763 return 0; 756 return 0;
764} 757}
765 758
766static struct snd_soc_codec *wm8988_codec; 759static int wm8988_probe(struct snd_soc_codec *codec)
767
768static int wm8988_probe(struct platform_device *pdev)
769{ 760{
770 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 761 struct wm8988_priv *wm8988 = snd_soc_codec_get_drvdata(codec);
771 struct snd_soc_codec *codec;
772 int ret = 0; 762 int ret = 0;
773
774 if (wm8988_codec == NULL) {
775 dev_err(&pdev->dev, "Codec device not registered\n");
776 return -ENODEV;
777 }
778
779 socdev->card->codec = wm8988_codec;
780 codec = wm8988_codec;
781
782 /* register pcms */
783 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
784 if (ret < 0) {
785 dev_err(codec->dev, "failed to create pcms: %d\n", ret);
786 goto pcm_err;
787 }
788
789 snd_soc_add_controls(codec, wm8988_snd_controls,
790 ARRAY_SIZE(wm8988_snd_controls));
791 snd_soc_dapm_new_controls(codec, wm8988_dapm_widgets,
792 ARRAY_SIZE(wm8988_dapm_widgets));
793 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
794
795 return ret;
796
797pcm_err:
798 return ret;
799}
800
801static int wm8988_remove(struct platform_device *pdev)
802{
803 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
804
805 snd_soc_free_pcms(socdev);
806 snd_soc_dapm_free(socdev);
807
808 return 0;
809}
810
811struct snd_soc_codec_device soc_codec_dev_wm8988 = {
812 .probe = wm8988_probe,
813 .remove = wm8988_remove,
814 .suspend = wm8988_suspend,
815 .resume = wm8988_resume,
816};
817EXPORT_SYMBOL_GPL(soc_codec_dev_wm8988);
818
819static int wm8988_register(struct wm8988_priv *wm8988,
820 enum snd_soc_control_type control)
821{
822 struct snd_soc_codec *codec = &wm8988->codec;
823 int ret;
824 u16 reg; 763 u16 reg;
825 764
826 if (wm8988_codec) { 765 ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8988->control_type);
827 dev_err(codec->dev, "Another WM8988 is registered\n");
828 ret = -EINVAL;
829 goto err;
830 }
831
832 mutex_init(&codec->mutex);
833 INIT_LIST_HEAD(&codec->dapm_widgets);
834 INIT_LIST_HEAD(&codec->dapm_paths);
835
836 snd_soc_codec_set_drvdata(codec, wm8988);
837 codec->name = "WM8988";
838 codec->owner = THIS_MODULE;
839 codec->dai = &wm8988_dai;
840 codec->num_dai = 1;
841 codec->reg_cache_size = ARRAY_SIZE(wm8988->reg_cache);
842 codec->reg_cache = &wm8988->reg_cache;
843 codec->bias_level = SND_SOC_BIAS_OFF;
844 codec->set_bias_level = wm8988_set_bias_level;
845
846 memcpy(codec->reg_cache, wm8988_reg,
847 sizeof(wm8988_reg));
848
849 ret = snd_soc_codec_set_cache_io(codec, 7, 9, control);
850 if (ret < 0) { 766 if (ret < 0) {
851 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); 767 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
852 goto err; 768 return ret;
853 } 769 }
854 770
855 ret = wm8988_reset(codec); 771 ret = wm8988_reset(codec);
856 if (ret < 0) { 772 if (ret < 0) {
857 dev_err(codec->dev, "Failed to issue reset\n"); 773 dev_err(codec->dev, "Failed to issue reset\n");
858 goto err; 774 return ret;
859 } 775 }
860 776
861 /* set the update bits (we always update left then right) */ 777 /* set the update bits (we always update left then right) */
@@ -870,139 +786,132 @@ static int wm8988_register(struct wm8988_priv *wm8988,
870 reg = snd_soc_read(codec, WM8988_RINVOL); 786 reg = snd_soc_read(codec, WM8988_RINVOL);
871 snd_soc_write(codec, WM8988_RINVOL, reg | 0x0100); 787 snd_soc_write(codec, WM8988_RINVOL, reg | 0x0100);
872 788
873 wm8988_set_bias_level(&wm8988->codec, SND_SOC_BIAS_STANDBY); 789 wm8988_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
874
875 wm8988_dai.dev = codec->dev;
876
877 wm8988_codec = codec;
878
879 ret = snd_soc_register_codec(codec);
880 if (ret != 0) {
881 dev_err(codec->dev, "Failed to register codec: %d\n", ret);
882 goto err;
883 }
884 790
885 ret = snd_soc_register_dai(&wm8988_dai); 791 snd_soc_add_controls(codec, wm8988_snd_controls,
886 if (ret != 0) { 792 ARRAY_SIZE(wm8988_snd_controls));
887 dev_err(codec->dev, "Failed to register DAI: %d\n", ret); 793 snd_soc_dapm_new_controls(codec, wm8988_dapm_widgets,
888 goto err_codec; 794 ARRAY_SIZE(wm8988_dapm_widgets));
889 } 795 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
890 796
891 return 0; 797 return 0;
892
893err_codec:
894 snd_soc_unregister_codec(codec);
895err:
896 kfree(wm8988);
897 return ret;
898} 798}
899 799
900static void wm8988_unregister(struct wm8988_priv *wm8988) 800static int wm8988_remove(struct snd_soc_codec *codec)
901{ 801{
902 wm8988_set_bias_level(&wm8988->codec, SND_SOC_BIAS_OFF); 802 wm8988_set_bias_level(codec, SND_SOC_BIAS_OFF);
903 snd_soc_unregister_dai(&wm8988_dai); 803 return 0;
904 snd_soc_unregister_codec(&wm8988->codec);
905 kfree(wm8988);
906 wm8988_codec = NULL;
907} 804}
908 805
909#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 806static struct snd_soc_codec_driver soc_codec_dev_wm8988 = {
910static int wm8988_i2c_probe(struct i2c_client *i2c, 807 .probe = wm8988_probe,
911 const struct i2c_device_id *id) 808 .remove = wm8988_remove,
809 .suspend = wm8988_suspend,
810 .resume = wm8988_resume,
811 .set_bias_level = wm8988_set_bias_level,
812 .reg_cache_size = ARRAY_SIZE(wm8988_reg),
813 .reg_word_size = sizeof(u16),
814 .reg_cache_default = wm8988_reg,
815};
816
817#if defined(CONFIG_SPI_MASTER)
818static int __devinit wm8988_spi_probe(struct spi_device *spi)
912{ 819{
913 struct wm8988_priv *wm8988; 820 struct wm8988_priv *wm8988;
914 struct snd_soc_codec *codec; 821 int ret;
915 822
916 wm8988 = kzalloc(sizeof(struct wm8988_priv), GFP_KERNEL); 823 wm8988 = kzalloc(sizeof(struct wm8988_priv), GFP_KERNEL);
917 if (wm8988 == NULL) 824 if (wm8988 == NULL)
918 return -ENOMEM; 825 return -ENOMEM;
919 826
920 codec = &wm8988->codec; 827 wm8988->control_type = SND_SOC_SPI;
921 828 spi_set_drvdata(spi, wm8988);
922 i2c_set_clientdata(i2c, wm8988);
923 codec->control_data = i2c;
924
925 codec->dev = &i2c->dev;
926 829
927 return wm8988_register(wm8988, SND_SOC_I2C); 830 ret = snd_soc_register_codec(&spi->dev,
831 &soc_codec_dev_wm8988, &wm8988_dai, 1);
832 if (ret < 0)
833 kfree(wm8988);
834 return ret;
928} 835}
929 836
930static int wm8988_i2c_remove(struct i2c_client *client) 837static int __devexit wm8988_spi_remove(struct spi_device *spi)
931{ 838{
932 struct wm8988_priv *wm8988 = i2c_get_clientdata(client); 839 snd_soc_unregister_codec(&spi->dev);
933 wm8988_unregister(wm8988); 840 kfree(spi_get_drvdata(spi));
934 return 0; 841 return 0;
935} 842}
936 843
937static const struct i2c_device_id wm8988_i2c_id[] = { 844static struct spi_driver wm8988_spi_driver = {
938 { "wm8988", 0 },
939 { }
940};
941MODULE_DEVICE_TABLE(i2c, wm8988_i2c_id);
942
943static struct i2c_driver wm8988_i2c_driver = {
944 .driver = { 845 .driver = {
945 .name = "WM8988", 846 .name = "wm8988-codec",
946 .owner = THIS_MODULE, 847 .owner = THIS_MODULE,
947 }, 848 },
948 .probe = wm8988_i2c_probe, 849 .probe = wm8988_spi_probe,
949 .remove = wm8988_i2c_remove, 850 .remove = __devexit_p(wm8988_spi_remove),
950 .id_table = wm8988_i2c_id,
951}; 851};
952#endif 852#endif /* CONFIG_SPI_MASTER */
953 853
954#if defined(CONFIG_SPI_MASTER) 854#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
955static int __devinit wm8988_spi_probe(struct spi_device *spi) 855static __devinit int wm8988_i2c_probe(struct i2c_client *i2c,
856 const struct i2c_device_id *id)
956{ 857{
957 struct wm8988_priv *wm8988; 858 struct wm8988_priv *wm8988;
958 struct snd_soc_codec *codec; 859 int ret;
959 860
960 wm8988 = kzalloc(sizeof(struct wm8988_priv), GFP_KERNEL); 861 wm8988 = kzalloc(sizeof(struct wm8988_priv), GFP_KERNEL);
961 if (wm8988 == NULL) 862 if (wm8988 == NULL)
962 return -ENOMEM; 863 return -ENOMEM;
963 864
964 codec = &wm8988->codec; 865 i2c_set_clientdata(i2c, wm8988);
965 codec->control_data = spi; 866 wm8988->control_type = SND_SOC_I2C;
966 codec->dev = &spi->dev;
967
968 dev_set_drvdata(&spi->dev, wm8988);
969 867
970 return wm8988_register(wm8988, SND_SOC_SPI); 868 ret = snd_soc_register_codec(&i2c->dev,
869 &soc_codec_dev_wm8988, &wm8988_dai, 1);
870 if (ret < 0)
871 kfree(wm8988);
872 return ret;
971} 873}
972 874
973static int __devexit wm8988_spi_remove(struct spi_device *spi) 875static __devexit int wm8988_i2c_remove(struct i2c_client *client)
974{ 876{
975 struct wm8988_priv *wm8988 = dev_get_drvdata(&spi->dev); 877 snd_soc_unregister_codec(&client->dev);
976 878 kfree(i2c_get_clientdata(client));
977 wm8988_unregister(wm8988);
978
979 return 0; 879 return 0;
980} 880}
981 881
982static struct spi_driver wm8988_spi_driver = { 882static const struct i2c_device_id wm8988_i2c_id[] = {
883 { "wm8988", 0 },
884 { }
885};
886MODULE_DEVICE_TABLE(i2c, wm8988_i2c_id);
887
888static struct i2c_driver wm8988_i2c_driver = {
983 .driver = { 889 .driver = {
984 .name = "wm8988", 890 .name = "wm8988-codec",
985 .bus = &spi_bus_type, 891 .owner = THIS_MODULE,
986 .owner = THIS_MODULE,
987 }, 892 },
988 .probe = wm8988_spi_probe, 893 .probe = wm8988_i2c_probe,
989 .remove = __devexit_p(wm8988_spi_remove), 894 .remove = __devexit_p(wm8988_i2c_remove),
895 .id_table = wm8988_i2c_id,
990}; 896};
991#endif 897#endif
992 898
993static int __init wm8988_modinit(void) 899static int __init wm8988_modinit(void)
994{ 900{
995 int ret; 901 int ret = 0;
996
997#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 902#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
998 ret = i2c_add_driver(&wm8988_i2c_driver); 903 ret = i2c_add_driver(&wm8988_i2c_driver);
999 if (ret != 0) 904 if (ret != 0) {
1000 pr_err("WM8988: Unable to register I2C driver: %d\n", ret); 905 printk(KERN_ERR "Failed to register WM8988 I2C driver: %d\n",
906 ret);
907 }
1001#endif 908#endif
1002#if defined(CONFIG_SPI_MASTER) 909#if defined(CONFIG_SPI_MASTER)
1003 ret = spi_register_driver(&wm8988_spi_driver); 910 ret = spi_register_driver(&wm8988_spi_driver);
1004 if (ret != 0) 911 if (ret != 0) {
1005 pr_err("WM8988: Unable to register SPI driver: %d\n", ret); 912 printk(KERN_ERR "Failed to register WM8988 SPI driver: %d\n",
913 ret);
914 }
1006#endif 915#endif
1007 return ret; 916 return ret;
1008} 917}