spdif_transciever.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * ALSA SoC SPDIF DIT driver
  3. *
  4. * This driver is used by controllers which can operate in DIT (SPDI/F) where
  5. * no codec is needed. This file provides stub codec that can be used
  6. * in these configurations. TI DaVinci Audio controller uses this driver.
  7. *
  8. * Author: Steve Chen, <schen@mvista.com>
  9. * Copyright: (C) 2009 MontaVista Software, Inc., <source@mvista.com>
  10. * Copyright: (C) 2009 Texas Instruments, India
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2 as
  14. * published by the Free Software Foundation.
  15. */
  16. #include <linux/module.h>
  17. #include <linux/moduleparam.h>
  18. #include <sound/soc.h>
  19. #include <sound/pcm.h>
  20. #include <sound/initval.h>
  21. #include "spdif_transciever.h"
  22. MODULE_LICENSE("GPL");
  23. #define STUB_RATES SNDRV_PCM_RATE_8000_96000
  24. #define STUB_FORMATS SNDRV_PCM_FMTBIT_S16_LE
  25. static struct snd_soc_codec *spdif_dit_codec;
  26. static int spdif_dit_codec_probe(struct platform_device *pdev)
  27. {
  28. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  29. struct snd_soc_codec *codec;
  30. int ret;
  31. if (spdif_dit_codec == NULL) {
  32. dev_err(&pdev->dev, "Codec device not registered\n");
  33. return -ENODEV;
  34. }
  35. socdev->card->codec = spdif_dit_codec;
  36. codec = spdif_dit_codec;
  37. ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
  38. if (ret < 0) {
  39. dev_err(codec->dev, "failed to create pcms: %d\n", ret);
  40. goto err_create_pcms;
  41. }
  42. return 0;
  43. err_create_pcms:
  44. return ret;
  45. }
  46. static int spdif_dit_codec_remove(struct platform_device *pdev)
  47. {
  48. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  49. snd_soc_free_pcms(socdev);
  50. return 0;
  51. }
  52. struct snd_soc_codec_device soc_codec_dev_spdif_dit = {
  53. .probe = spdif_dit_codec_probe,
  54. .remove = spdif_dit_codec_remove,
  55. }; EXPORT_SYMBOL_GPL(soc_codec_dev_spdif_dit);
  56. struct snd_soc_dai dit_stub_dai = {
  57. .name = "DIT",
  58. .playback = {
  59. .stream_name = "Playback",
  60. .channels_min = 1,
  61. .channels_max = 384,
  62. .rates = STUB_RATES,
  63. .formats = STUB_FORMATS,
  64. },
  65. };
  66. EXPORT_SYMBOL_GPL(dit_stub_dai);
  67. static int spdif_dit_probe(struct platform_device *pdev)
  68. {
  69. struct snd_soc_codec *codec;
  70. int ret;
  71. if (spdif_dit_codec) {
  72. dev_err(&pdev->dev, "Another Codec is registered\n");
  73. ret = -EINVAL;
  74. goto err_reg_codec;
  75. }
  76. codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
  77. if (codec == NULL)
  78. return -ENOMEM;
  79. codec->dev = &pdev->dev;
  80. mutex_init(&codec->mutex);
  81. INIT_LIST_HEAD(&codec->dapm_widgets);
  82. INIT_LIST_HEAD(&codec->dapm_paths);
  83. codec->name = "spdif-dit";
  84. codec->owner = THIS_MODULE;
  85. codec->dai = &dit_stub_dai;
  86. codec->num_dai = 1;
  87. spdif_dit_codec = codec;
  88. ret = snd_soc_register_codec(codec);
  89. if (ret < 0) {
  90. dev_err(codec->dev, "Failed to register codec: %d\n", ret);
  91. goto err_reg_codec;
  92. }
  93. dit_stub_dai.dev = &pdev->dev;
  94. ret = snd_soc_register_dai(&dit_stub_dai);
  95. if (ret < 0) {
  96. dev_err(codec->dev, "Failed to register dai: %d\n", ret);
  97. goto err_reg_dai;
  98. }
  99. return 0;
  100. err_reg_dai:
  101. snd_soc_unregister_codec(codec);
  102. err_reg_codec:
  103. kfree(spdif_dit_codec);
  104. return ret;
  105. }
  106. static int spdif_dit_remove(struct platform_device *pdev)
  107. {
  108. snd_soc_unregister_dai(&dit_stub_dai);
  109. snd_soc_unregister_codec(spdif_dit_codec);
  110. kfree(spdif_dit_codec);
  111. spdif_dit_codec = NULL;
  112. return 0;
  113. }
  114. static struct platform_driver spdif_dit_driver = {
  115. .probe = spdif_dit_probe,
  116. .remove = spdif_dit_remove,
  117. .driver = {
  118. .name = "spdif-dit",
  119. .owner = THIS_MODULE,
  120. },
  121. };
  122. static int __init dit_modinit(void)
  123. {
  124. return platform_driver_register(&spdif_dit_driver);
  125. }
  126. static void __exit dit_exit(void)
  127. {
  128. platform_driver_unregister(&spdif_dit_driver);
  129. }
  130. module_init(dit_modinit);
  131. module_exit(dit_exit);