spdif_transciever.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 <linux/slab.h>
  19. #include <sound/soc.h>
  20. #include <sound/pcm.h>
  21. #include <sound/initval.h>
  22. #include "spdif_transciever.h"
  23. MODULE_LICENSE("GPL");
  24. #define STUB_RATES SNDRV_PCM_RATE_8000_96000
  25. #define STUB_FORMATS SNDRV_PCM_FMTBIT_S16_LE
  26. static struct snd_soc_codec *spdif_dit_codec;
  27. static int spdif_dit_codec_probe(struct platform_device *pdev)
  28. {
  29. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  30. struct snd_soc_codec *codec;
  31. int ret;
  32. if (spdif_dit_codec == NULL) {
  33. dev_err(&pdev->dev, "Codec device not registered\n");
  34. return -ENODEV;
  35. }
  36. socdev->card->codec = spdif_dit_codec;
  37. codec = spdif_dit_codec;
  38. ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
  39. if (ret < 0) {
  40. dev_err(codec->dev, "failed to create pcms: %d\n", ret);
  41. goto err_create_pcms;
  42. }
  43. return 0;
  44. err_create_pcms:
  45. return ret;
  46. }
  47. static int spdif_dit_codec_remove(struct platform_device *pdev)
  48. {
  49. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  50. snd_soc_free_pcms(socdev);
  51. return 0;
  52. }
  53. struct snd_soc_codec_device soc_codec_dev_spdif_dit = {
  54. .probe = spdif_dit_codec_probe,
  55. .remove = spdif_dit_codec_remove,
  56. }; EXPORT_SYMBOL_GPL(soc_codec_dev_spdif_dit);
  57. struct snd_soc_dai dit_stub_dai = {
  58. .name = "DIT",
  59. .playback = {
  60. .stream_name = "Playback",
  61. .channels_min = 1,
  62. .channels_max = 384,
  63. .rates = STUB_RATES,
  64. .formats = STUB_FORMATS,
  65. },
  66. };
  67. EXPORT_SYMBOL_GPL(dit_stub_dai);
  68. static int spdif_dit_probe(struct platform_device *pdev)
  69. {
  70. struct snd_soc_codec *codec;
  71. int ret;
  72. if (spdif_dit_codec) {
  73. dev_err(&pdev->dev, "Another Codec is registered\n");
  74. ret = -EINVAL;
  75. goto err_reg_codec;
  76. }
  77. codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
  78. if (codec == NULL)
  79. return -ENOMEM;
  80. codec->dev = &pdev->dev;
  81. mutex_init(&codec->mutex);
  82. INIT_LIST_HEAD(&codec->dapm_widgets);
  83. INIT_LIST_HEAD(&codec->dapm_paths);
  84. codec->name = "spdif-dit";
  85. codec->owner = THIS_MODULE;
  86. codec->dai = &dit_stub_dai;
  87. codec->num_dai = 1;
  88. spdif_dit_codec = codec;
  89. ret = snd_soc_register_codec(codec);
  90. if (ret < 0) {
  91. dev_err(codec->dev, "Failed to register codec: %d\n", ret);
  92. goto err_reg_codec;
  93. }
  94. dit_stub_dai.dev = &pdev->dev;
  95. ret = snd_soc_register_dai(&dit_stub_dai);
  96. if (ret < 0) {
  97. dev_err(codec->dev, "Failed to register dai: %d\n", ret);
  98. goto err_reg_dai;
  99. }
  100. return 0;
  101. err_reg_dai:
  102. snd_soc_unregister_codec(codec);
  103. err_reg_codec:
  104. kfree(spdif_dit_codec);
  105. return ret;
  106. }
  107. static int spdif_dit_remove(struct platform_device *pdev)
  108. {
  109. snd_soc_unregister_dai(&dit_stub_dai);
  110. snd_soc_unregister_codec(spdif_dit_codec);
  111. kfree(spdif_dit_codec);
  112. spdif_dit_codec = NULL;
  113. return 0;
  114. }
  115. static struct platform_driver spdif_dit_driver = {
  116. .probe = spdif_dit_probe,
  117. .remove = spdif_dit_remove,
  118. .driver = {
  119. .name = "spdif-dit",
  120. .owner = THIS_MODULE,
  121. },
  122. };
  123. static int __init dit_modinit(void)
  124. {
  125. return platform_driver_register(&spdif_dit_driver);
  126. }
  127. static void __exit dit_exit(void)
  128. {
  129. platform_driver_unregister(&spdif_dit_driver);
  130. }
  131. module_init(dit_modinit);
  132. module_exit(dit_exit);