lpass-i2s.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/init.h>
  13. #include <linux/module.h>
  14. #include <linux/device.h>
  15. #include <linux/delay.h>
  16. #include <linux/clk.h>
  17. #include <linux/platform_device.h>
  18. #include <sound/core.h>
  19. #include <sound/pcm.h>
  20. #include <sound/initval.h>
  21. #include <sound/soc.h>
  22. #include <sound/dai.h>
  23. static int msm_cpu_dai_startup(struct snd_pcm_substream *substream,
  24. struct snd_soc_dai *dai)
  25. {
  26. uint32_t dma_ch = dai->id;
  27. int ret = 0;
  28. pr_debug("%s\n", __func__);
  29. ret = dai_open(dma_ch);
  30. return ret;
  31. }
  32. static void msm_cpu_dai_shutdown(struct snd_pcm_substream *substream,
  33. struct snd_soc_dai *dai)
  34. {
  35. uint32_t dma_ch = dai->id;
  36. pr_debug("%s\n", __func__);
  37. dai_close(dma_ch);
  38. }
  39. static int msm_cpu_dai_trigger(struct snd_pcm_substream *substream, int cmd,
  40. struct snd_soc_dai *dai)
  41. {
  42. pr_debug("%s\n", __func__);
  43. return 0;
  44. }
  45. static int msm_cpu_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  46. {
  47. uint32_t dma_ch = dai->id;
  48. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  49. case SND_SOC_DAIFMT_CBS_CFS:
  50. dai_set_master_mode(dma_ch, 1); /* CPU is master */
  51. break;
  52. case SND_SOC_DAIFMT_CBM_CFM:
  53. dai_set_master_mode(dma_ch, 0); /* CPU is slave */
  54. break;
  55. default:
  56. return -EINVAL;
  57. }
  58. return 0;
  59. }
  60. static struct snd_soc_dai_ops msm_cpu_dai_ops = {
  61. .startup = msm_cpu_dai_startup,
  62. .shutdown = msm_cpu_dai_shutdown,
  63. .trigger = msm_cpu_dai_trigger,
  64. .set_fmt = msm_cpu_dai_fmt,
  65. };
  66. #define MSM_DAI_SPEAKER_BUILDER(link_id) \
  67. { \
  68. .name = "msm-speaker-dai-"#link_id, \
  69. .id = (link_id), \
  70. .playback = { \
  71. .rates = SNDRV_PCM_RATE_8000_96000, \
  72. .formats = SNDRV_PCM_FMTBIT_S16_LE, \
  73. .channels_min = 1, \
  74. .channels_max = 2, \
  75. .rate_max = 96000, \
  76. .rate_min = 8000, \
  77. }, \
  78. .ops = &msm_cpu_dai_ops, \
  79. }
  80. #define MSM_DAI_MIC_BUILDER(link_id) \
  81. { \
  82. .name = "msm-mic-dai-"#link_id, \
  83. .id = (link_id), \
  84. .capture = { \
  85. .rates = SNDRV_PCM_RATE_8000_96000, \
  86. .formats = SNDRV_PCM_FMTBIT_S16_LE, \
  87. .rate_min = 8000, \
  88. .rate_max = 96000, \
  89. .channels_min = 1, \
  90. .channels_max = 2, \
  91. }, \
  92. .ops = &msm_cpu_dai_ops, \
  93. }
  94. struct snd_soc_dai msm_cpu_dai[] = {
  95. MSM_DAI_SPEAKER_BUILDER(0),
  96. MSM_DAI_SPEAKER_BUILDER(1),
  97. MSM_DAI_SPEAKER_BUILDER(2),
  98. MSM_DAI_SPEAKER_BUILDER(3),
  99. MSM_DAI_SPEAKER_BUILDER(4),
  100. MSM_DAI_MIC_BUILDER(5),
  101. MSM_DAI_MIC_BUILDER(6),
  102. MSM_DAI_MIC_BUILDER(7),
  103. };
  104. EXPORT_SYMBOL_GPL(msm_cpu_dai);
  105. static int __init msm_cpu_dai_init(void)
  106. {
  107. return snd_soc_register_dais(msm_cpu_dai, ARRAY_SIZE(msm_cpu_dai));
  108. }
  109. module_init(msm_cpu_dai_init);
  110. static void __exit msm_cpu_dai_exit(void)
  111. {
  112. snd_soc_unregister_dais(msm_cpu_dai, ARRAY_SIZE(msm_cpu_dai));
  113. }
  114. module_exit(msm_cpu_dai_exit);
  115. /* Module information */
  116. MODULE_DESCRIPTION("MSM CPU DAI driver");
  117. MODULE_LICENSE("GPL v2");