apq8096.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (c) 2018, Linaro Limited
  3. #include <linux/module.h>
  4. #include <linux/platform_device.h>
  5. #include <linux/of_device.h>
  6. #include <sound/soc.h>
  7. #include <sound/soc-dapm.h>
  8. #include <sound/pcm.h>
  9. #include "common.h"
  10. #define SLIM_MAX_TX_PORTS 16
  11. #define SLIM_MAX_RX_PORTS 16
  12. #define WCD9335_DEFAULT_MCLK_RATE 9600000
  13. static int apq8096_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
  14. struct snd_pcm_hw_params *params)
  15. {
  16. struct snd_interval *rate = hw_param_interval(params,
  17. SNDRV_PCM_HW_PARAM_RATE);
  18. struct snd_interval *channels = hw_param_interval(params,
  19. SNDRV_PCM_HW_PARAM_CHANNELS);
  20. rate->min = rate->max = 48000;
  21. channels->min = channels->max = 2;
  22. return 0;
  23. }
  24. static int msm_snd_hw_params(struct snd_pcm_substream *substream,
  25. struct snd_pcm_hw_params *params)
  26. {
  27. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  28. struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
  29. struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
  30. u32 rx_ch[SLIM_MAX_RX_PORTS], tx_ch[SLIM_MAX_TX_PORTS];
  31. u32 rx_ch_cnt = 0, tx_ch_cnt = 0;
  32. int ret = 0;
  33. ret = snd_soc_dai_get_channel_map(codec_dai,
  34. &tx_ch_cnt, tx_ch, &rx_ch_cnt, rx_ch);
  35. if (ret != 0 && ret != -ENOTSUPP) {
  36. pr_err("failed to get codec chan map, err:%d\n", ret);
  37. goto end;
  38. } else if (ret == -ENOTSUPP) {
  39. return 0;
  40. }
  41. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  42. ret = snd_soc_dai_set_channel_map(cpu_dai, 0, NULL,
  43. rx_ch_cnt, rx_ch);
  44. else
  45. ret = snd_soc_dai_set_channel_map(cpu_dai, tx_ch_cnt, tx_ch,
  46. 0, NULL);
  47. if (ret != 0 && ret != -ENOTSUPP)
  48. pr_err("Failed to set cpu chan map, err:%d\n", ret);
  49. else if (ret == -ENOTSUPP)
  50. ret = 0;
  51. end:
  52. return ret;
  53. }
  54. static const struct snd_soc_ops apq8096_ops = {
  55. .hw_params = msm_snd_hw_params,
  56. };
  57. static int apq8096_init(struct snd_soc_pcm_runtime *rtd)
  58. {
  59. struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
  60. /*
  61. * Codec SLIMBUS configuration
  62. * RX1, RX2, RX3, RX4, RX5, RX6, RX7, RX8, RX9, RX10, RX11, RX12, RX13
  63. * TX1, TX2, TX3, TX4, TX5, TX6, TX7, TX8, TX9, TX10, TX11, TX12, TX13
  64. * TX14, TX15, TX16
  65. */
  66. unsigned int rx_ch[SLIM_MAX_RX_PORTS] = {144, 145, 146, 147, 148, 149,
  67. 150, 151, 152, 153, 154, 155, 156};
  68. unsigned int tx_ch[SLIM_MAX_TX_PORTS] = {128, 129, 130, 131, 132, 133,
  69. 134, 135, 136, 137, 138, 139,
  70. 140, 141, 142, 143};
  71. snd_soc_dai_set_channel_map(codec_dai, ARRAY_SIZE(tx_ch),
  72. tx_ch, ARRAY_SIZE(rx_ch), rx_ch);
  73. snd_soc_dai_set_sysclk(codec_dai, 0, WCD9335_DEFAULT_MCLK_RATE,
  74. SNDRV_PCM_STREAM_PLAYBACK);
  75. return 0;
  76. }
  77. static void apq8096_add_be_ops(struct snd_soc_card *card)
  78. {
  79. struct snd_soc_dai_link *link;
  80. int i;
  81. for_each_card_prelinks(card, i, link) {
  82. if (link->no_pcm == 1) {
  83. link->be_hw_params_fixup = apq8096_be_hw_params_fixup;
  84. link->init = apq8096_init;
  85. link->ops = &apq8096_ops;
  86. }
  87. }
  88. }
  89. static int apq8096_platform_probe(struct platform_device *pdev)
  90. {
  91. struct snd_soc_card *card;
  92. struct device *dev = &pdev->dev;
  93. int ret;
  94. card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
  95. if (!card)
  96. return -ENOMEM;
  97. card->dev = dev;
  98. card->owner = THIS_MODULE;
  99. dev_set_drvdata(dev, card);
  100. ret = qcom_snd_parse_of(card);
  101. if (ret)
  102. return ret;
  103. apq8096_add_be_ops(card);
  104. return devm_snd_soc_register_card(dev, card);
  105. }
  106. static const struct of_device_id msm_snd_apq8096_dt_match[] = {
  107. {.compatible = "qcom,apq8096-sndcard"},
  108. {}
  109. };
  110. MODULE_DEVICE_TABLE(of, msm_snd_apq8096_dt_match);
  111. static struct platform_driver msm_snd_apq8096_driver = {
  112. .probe = apq8096_platform_probe,
  113. .driver = {
  114. .name = "msm-snd-apq8096",
  115. .of_match_table = msm_snd_apq8096_dt_match,
  116. },
  117. };
  118. module_platform_driver(msm_snd_apq8096_driver);
  119. MODULE_AUTHOR("Srinivas Kandagatla <[email protected]");
  120. MODULE_DESCRIPTION("APQ8096 ASoC Machine Driver");
  121. MODULE_LICENSE("GPL v2");