lpass-apq8016.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*
  2. * Copyright (c) 2010-2011,2013-2015 The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * lpass-apq8016.c -- ALSA SoC CPU DAI driver for APQ8016 LPASS
  14. *
  15. */
  16. #include <linux/clk.h>
  17. #include <linux/device.h>
  18. #include <linux/err.h>
  19. #include <linux/kernel.h>
  20. #include <linux/module.h>
  21. #include <linux/of.h>
  22. #include <linux/platform_device.h>
  23. #include <sound/pcm.h>
  24. #include <sound/pcm_params.h>
  25. #include <sound/soc.h>
  26. #include <sound/soc-dai.h>
  27. #include <dt-bindings/sound/apq8016-lpass.h>
  28. #include "lpass-lpaif-reg.h"
  29. #include "lpass.h"
  30. static struct snd_soc_dai_driver apq8016_lpass_cpu_dai_driver[] = {
  31. [MI2S_PRIMARY] = {
  32. .id = MI2S_PRIMARY,
  33. .name = "Primary MI2S",
  34. .playback = {
  35. .stream_name = "Primary Playback",
  36. .formats = SNDRV_PCM_FMTBIT_S16 |
  37. SNDRV_PCM_FMTBIT_S24 |
  38. SNDRV_PCM_FMTBIT_S32,
  39. .rates = SNDRV_PCM_RATE_8000 |
  40. SNDRV_PCM_RATE_16000 |
  41. SNDRV_PCM_RATE_32000 |
  42. SNDRV_PCM_RATE_48000 |
  43. SNDRV_PCM_RATE_96000,
  44. .rate_min = 8000,
  45. .rate_max = 96000,
  46. .channels_min = 1,
  47. .channels_max = 8,
  48. },
  49. .probe = &asoc_qcom_lpass_cpu_dai_probe,
  50. .ops = &asoc_qcom_lpass_cpu_dai_ops,
  51. },
  52. [MI2S_SECONDARY] = {
  53. .id = MI2S_SECONDARY,
  54. .name = "Secondary MI2S",
  55. .playback = {
  56. .stream_name = "Secondary Playback",
  57. .formats = SNDRV_PCM_FMTBIT_S16 |
  58. SNDRV_PCM_FMTBIT_S24 |
  59. SNDRV_PCM_FMTBIT_S32,
  60. .rates = SNDRV_PCM_RATE_8000 |
  61. SNDRV_PCM_RATE_16000 |
  62. SNDRV_PCM_RATE_32000 |
  63. SNDRV_PCM_RATE_48000 |
  64. SNDRV_PCM_RATE_96000,
  65. .rate_min = 8000,
  66. .rate_max = 96000,
  67. .channels_min = 1,
  68. .channels_max = 8,
  69. },
  70. .probe = &asoc_qcom_lpass_cpu_dai_probe,
  71. .ops = &asoc_qcom_lpass_cpu_dai_ops,
  72. },
  73. [MI2S_TERTIARY] = {
  74. .id = MI2S_TERTIARY,
  75. .name = "Tertiary MI2S",
  76. .capture = {
  77. .stream_name = "Tertiary Capture",
  78. .formats = SNDRV_PCM_FMTBIT_S16 |
  79. SNDRV_PCM_FMTBIT_S24 |
  80. SNDRV_PCM_FMTBIT_S32,
  81. .rates = SNDRV_PCM_RATE_8000 |
  82. SNDRV_PCM_RATE_16000 |
  83. SNDRV_PCM_RATE_32000 |
  84. SNDRV_PCM_RATE_48000 |
  85. SNDRV_PCM_RATE_96000,
  86. .rate_min = 8000,
  87. .rate_max = 96000,
  88. .channels_min = 1,
  89. .channels_max = 8,
  90. },
  91. .probe = &asoc_qcom_lpass_cpu_dai_probe,
  92. .ops = &asoc_qcom_lpass_cpu_dai_ops,
  93. },
  94. [MI2S_QUATERNARY] = {
  95. .id = MI2S_QUATERNARY,
  96. .name = "Quatenary MI2S",
  97. .playback = {
  98. .stream_name = "Quatenary Playback",
  99. .formats = SNDRV_PCM_FMTBIT_S16 |
  100. SNDRV_PCM_FMTBIT_S24 |
  101. SNDRV_PCM_FMTBIT_S32,
  102. .rates = SNDRV_PCM_RATE_8000 |
  103. SNDRV_PCM_RATE_16000 |
  104. SNDRV_PCM_RATE_32000 |
  105. SNDRV_PCM_RATE_48000 |
  106. SNDRV_PCM_RATE_96000,
  107. .rate_min = 8000,
  108. .rate_max = 96000,
  109. .channels_min = 1,
  110. .channels_max = 8,
  111. },
  112. .capture = {
  113. .stream_name = "Quatenary Capture",
  114. .formats = SNDRV_PCM_FMTBIT_S16 |
  115. SNDRV_PCM_FMTBIT_S24 |
  116. SNDRV_PCM_FMTBIT_S32,
  117. .rates = SNDRV_PCM_RATE_8000 |
  118. SNDRV_PCM_RATE_16000 |
  119. SNDRV_PCM_RATE_32000 |
  120. SNDRV_PCM_RATE_48000 |
  121. SNDRV_PCM_RATE_96000,
  122. .rate_min = 8000,
  123. .rate_max = 96000,
  124. .channels_min = 1,
  125. .channels_max = 8,
  126. },
  127. .probe = &asoc_qcom_lpass_cpu_dai_probe,
  128. .ops = &asoc_qcom_lpass_cpu_dai_ops,
  129. },
  130. };
  131. static int apq8016_lpass_alloc_dma_channel(struct lpass_data *drvdata)
  132. {
  133. struct lpass_variant *v = drvdata->variant;
  134. int chan = find_first_zero_bit(&drvdata->rdma_ch_bit_map,
  135. v->rdma_channels);
  136. if (chan >= v->rdma_channels)
  137. return -EBUSY;
  138. set_bit(chan, &drvdata->rdma_ch_bit_map);
  139. return chan;
  140. }
  141. static int apq8016_lpass_free_dma_channel(struct lpass_data *drvdata, int chan)
  142. {
  143. clear_bit(chan, &drvdata->rdma_ch_bit_map);
  144. return 0;
  145. }
  146. static int apq8016_lpass_init(struct platform_device *pdev)
  147. {
  148. struct lpass_data *drvdata = platform_get_drvdata(pdev);
  149. struct device *dev = &pdev->dev;
  150. int ret;
  151. drvdata->pcnoc_mport_clk = devm_clk_get(dev, "pcnoc-mport-clk");
  152. if (IS_ERR(drvdata->pcnoc_mport_clk)) {
  153. dev_err(&pdev->dev, "%s() error getting pcnoc-mport-clk: %ld\n",
  154. __func__, PTR_ERR(drvdata->pcnoc_mport_clk));
  155. return PTR_ERR(drvdata->pcnoc_mport_clk);
  156. }
  157. ret = clk_prepare_enable(drvdata->pcnoc_mport_clk);
  158. if (ret) {
  159. dev_err(&pdev->dev, "%s() Error enabling pcnoc-mport-clk: %d\n",
  160. __func__, ret);
  161. return ret;
  162. }
  163. drvdata->pcnoc_sway_clk = devm_clk_get(dev, "pcnoc-sway-clk");
  164. if (IS_ERR(drvdata->pcnoc_sway_clk)) {
  165. dev_err(&pdev->dev, "%s() error getting pcnoc-sway-clk: %ld\n",
  166. __func__, PTR_ERR(drvdata->pcnoc_sway_clk));
  167. return PTR_ERR(drvdata->pcnoc_sway_clk);
  168. }
  169. ret = clk_prepare_enable(drvdata->pcnoc_sway_clk);
  170. if (ret) {
  171. dev_err(&pdev->dev, "%s() Error enabling pcnoc_sway_clk: %d\n",
  172. __func__, ret);
  173. return ret;
  174. }
  175. return 0;
  176. }
  177. static int apq8016_lpass_exit(struct platform_device *pdev)
  178. {
  179. struct lpass_data *drvdata = platform_get_drvdata(pdev);
  180. clk_disable_unprepare(drvdata->pcnoc_mport_clk);
  181. clk_disable_unprepare(drvdata->pcnoc_sway_clk);
  182. return 0;
  183. }
  184. static struct lpass_variant apq8016_data = {
  185. .i2sctrl_reg_base = 0x1000,
  186. .i2sctrl_reg_stride = 0x1000,
  187. .i2s_ports = 4,
  188. .irq_reg_base = 0x6000,
  189. .irq_reg_stride = 0x1000,
  190. .irq_ports = 3,
  191. .rdma_reg_base = 0x8400,
  192. .rdma_reg_stride = 0x1000,
  193. .rdma_channels = 2,
  194. .rdmactl_audif_start = 1,
  195. .dai_driver = apq8016_lpass_cpu_dai_driver,
  196. .num_dai = ARRAY_SIZE(apq8016_lpass_cpu_dai_driver),
  197. .init = apq8016_lpass_init,
  198. .exit = apq8016_lpass_exit,
  199. .alloc_dma_channel = apq8016_lpass_alloc_dma_channel,
  200. .free_dma_channel = apq8016_lpass_free_dma_channel,
  201. };
  202. static const struct of_device_id apq8016_lpass_cpu_device_id[] = {
  203. { .compatible = "qcom,lpass-cpu-apq8016", .data = &apq8016_data },
  204. {}
  205. };
  206. MODULE_DEVICE_TABLE(of, apq8016_lpass_cpu_device_id);
  207. static struct platform_driver apq8016_lpass_cpu_platform_driver = {
  208. .driver = {
  209. .name = "apq8016-lpass-cpu",
  210. .of_match_table = of_match_ptr(apq8016_lpass_cpu_device_id),
  211. },
  212. .probe = asoc_qcom_lpass_cpu_platform_probe,
  213. .remove = asoc_qcom_lpass_cpu_platform_remove,
  214. };
  215. module_platform_driver(apq8016_lpass_cpu_platform_driver);
  216. MODULE_DESCRIPTION("APQ8016 LPASS CPU Driver");
  217. MODULE_LICENSE("GPL v2");