sc8280xp.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (c) 2022, 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 <linux/soundwire/sdw.h>
  10. #include <sound/jack.h>
  11. #include <linux/input-event-codes.h>
  12. #include "qdsp6/q6afe.h"
  13. #include "common.h"
  14. #include "sdw.h"
  15. #define DRIVER_NAME "sc8280xp"
  16. struct sc8280xp_snd_data {
  17. bool stream_prepared[AFE_PORT_MAX];
  18. struct snd_soc_card *card;
  19. struct sdw_stream_runtime *sruntime[AFE_PORT_MAX];
  20. struct snd_soc_jack jack;
  21. bool jack_setup;
  22. };
  23. static int sc8280xp_snd_init(struct snd_soc_pcm_runtime *rtd)
  24. {
  25. struct sc8280xp_snd_data *data = snd_soc_card_get_drvdata(rtd->card);
  26. return qcom_snd_wcd_jack_setup(rtd, &data->jack, &data->jack_setup);
  27. }
  28. static int sc8280xp_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
  29. struct snd_pcm_hw_params *params)
  30. {
  31. struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
  32. struct snd_interval *rate = hw_param_interval(params,
  33. SNDRV_PCM_HW_PARAM_RATE);
  34. struct snd_interval *channels = hw_param_interval(params,
  35. SNDRV_PCM_HW_PARAM_CHANNELS);
  36. rate->min = rate->max = 48000;
  37. channels->min = 2;
  38. channels->max = 2;
  39. switch (cpu_dai->id) {
  40. case TX_CODEC_DMA_TX_0:
  41. case TX_CODEC_DMA_TX_1:
  42. case TX_CODEC_DMA_TX_2:
  43. case TX_CODEC_DMA_TX_3:
  44. channels->min = 1;
  45. break;
  46. default:
  47. break;
  48. }
  49. return 0;
  50. }
  51. static int sc8280xp_snd_hw_params(struct snd_pcm_substream *substream,
  52. struct snd_pcm_hw_params *params)
  53. {
  54. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  55. struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
  56. struct sc8280xp_snd_data *pdata = snd_soc_card_get_drvdata(rtd->card);
  57. return qcom_snd_sdw_hw_params(substream, params, &pdata->sruntime[cpu_dai->id]);
  58. }
  59. static int sc8280xp_snd_prepare(struct snd_pcm_substream *substream)
  60. {
  61. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  62. struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
  63. struct sc8280xp_snd_data *data = snd_soc_card_get_drvdata(rtd->card);
  64. struct sdw_stream_runtime *sruntime = data->sruntime[cpu_dai->id];
  65. return qcom_snd_sdw_prepare(substream, sruntime,
  66. &data->stream_prepared[cpu_dai->id]);
  67. }
  68. static int sc8280xp_snd_hw_free(struct snd_pcm_substream *substream)
  69. {
  70. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  71. struct sc8280xp_snd_data *data = snd_soc_card_get_drvdata(rtd->card);
  72. struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
  73. struct sdw_stream_runtime *sruntime = data->sruntime[cpu_dai->id];
  74. return qcom_snd_sdw_hw_free(substream, sruntime,
  75. &data->stream_prepared[cpu_dai->id]);
  76. }
  77. static const struct snd_soc_ops sc8280xp_be_ops = {
  78. .hw_params = sc8280xp_snd_hw_params,
  79. .hw_free = sc8280xp_snd_hw_free,
  80. .prepare = sc8280xp_snd_prepare,
  81. };
  82. static void sc8280xp_add_be_ops(struct snd_soc_card *card)
  83. {
  84. struct snd_soc_dai_link *link;
  85. int i;
  86. for_each_card_prelinks(card, i, link) {
  87. if (link->no_pcm == 1) {
  88. link->init = sc8280xp_snd_init;
  89. link->be_hw_params_fixup = sc8280xp_be_hw_params_fixup;
  90. link->ops = &sc8280xp_be_ops;
  91. }
  92. }
  93. }
  94. static int sc8280xp_platform_probe(struct platform_device *pdev)
  95. {
  96. struct snd_soc_card *card;
  97. struct sc8280xp_snd_data *data;
  98. struct device *dev = &pdev->dev;
  99. int ret;
  100. card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
  101. if (!card)
  102. return -ENOMEM;
  103. card->owner = THIS_MODULE;
  104. /* Allocate the private data */
  105. data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
  106. if (!data)
  107. return -ENOMEM;
  108. card->dev = dev;
  109. dev_set_drvdata(dev, card);
  110. snd_soc_card_set_drvdata(card, data);
  111. ret = qcom_snd_parse_of(card);
  112. if (ret)
  113. return ret;
  114. card->driver_name = DRIVER_NAME;
  115. sc8280xp_add_be_ops(card);
  116. return devm_snd_soc_register_card(dev, card);
  117. }
  118. static const struct of_device_id snd_sc8280xp_dt_match[] = {
  119. {.compatible = "qcom,sc8280xp-sndcard",},
  120. {}
  121. };
  122. MODULE_DEVICE_TABLE(of, snd_sc8280xp_dt_match);
  123. static struct platform_driver snd_sc8280xp_driver = {
  124. .probe = sc8280xp_platform_probe,
  125. .driver = {
  126. .name = "snd-sc8280xp",
  127. .of_match_table = snd_sc8280xp_dt_match,
  128. },
  129. };
  130. module_platform_driver(snd_sc8280xp_driver);
  131. MODULE_AUTHOR("Srinivas Kandagatla <[email protected]");
  132. MODULE_DESCRIPTION("SC8280XP ASoC Machine Driver");
  133. MODULE_LICENSE("GPL v2");