apq8096.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. static int apq8096_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
  11. struct snd_pcm_hw_params *params)
  12. {
  13. struct snd_interval *rate = hw_param_interval(params,
  14. SNDRV_PCM_HW_PARAM_RATE);
  15. struct snd_interval *channels = hw_param_interval(params,
  16. SNDRV_PCM_HW_PARAM_CHANNELS);
  17. rate->min = rate->max = 48000;
  18. channels->min = channels->max = 2;
  19. return 0;
  20. }
  21. static void apq8096_add_be_ops(struct snd_soc_card *card)
  22. {
  23. struct snd_soc_dai_link *link = card->dai_link;
  24. int i, num_links = card->num_links;
  25. for (i = 0; i < num_links; i++) {
  26. if (link->no_pcm == 1)
  27. link->be_hw_params_fixup = apq8096_be_hw_params_fixup;
  28. link++;
  29. }
  30. }
  31. static int apq8096_platform_probe(struct platform_device *pdev)
  32. {
  33. struct snd_soc_card *card;
  34. struct device *dev = &pdev->dev;
  35. int ret;
  36. card = kzalloc(sizeof(*card), GFP_KERNEL);
  37. if (!card)
  38. return -ENOMEM;
  39. card->dev = dev;
  40. dev_set_drvdata(dev, card);
  41. ret = qcom_snd_parse_of(card);
  42. if (ret) {
  43. dev_err(dev, "Error parsing OF data\n");
  44. goto err;
  45. }
  46. apq8096_add_be_ops(card);
  47. ret = snd_soc_register_card(card);
  48. if (ret)
  49. goto err_card_register;
  50. return 0;
  51. err_card_register:
  52. kfree(card->dai_link);
  53. err:
  54. kfree(card);
  55. return ret;
  56. }
  57. static int apq8096_platform_remove(struct platform_device *pdev)
  58. {
  59. struct snd_soc_card *card = dev_get_drvdata(&pdev->dev);
  60. snd_soc_unregister_card(card);
  61. kfree(card->dai_link);
  62. kfree(card);
  63. return 0;
  64. }
  65. static const struct of_device_id msm_snd_apq8096_dt_match[] = {
  66. {.compatible = "qcom,apq8096-sndcard"},
  67. {}
  68. };
  69. MODULE_DEVICE_TABLE(of, msm_snd_apq8096_dt_match);
  70. static struct platform_driver msm_snd_apq8096_driver = {
  71. .probe = apq8096_platform_probe,
  72. .remove = apq8096_platform_remove,
  73. .driver = {
  74. .name = "msm-snd-apq8096",
  75. .of_match_table = msm_snd_apq8096_dt_match,
  76. },
  77. };
  78. module_platform_driver(msm_snd_apq8096_driver);
  79. MODULE_AUTHOR("Srinivas Kandagatla <srinivas.kandagatla@linaro.org");
  80. MODULE_DESCRIPTION("APQ8096 ASoC Machine Driver");
  81. MODULE_LICENSE("GPL v2");