apq8096.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. card->owner = THIS_MODULE;
  41. dev_set_drvdata(dev, card);
  42. ret = qcom_snd_parse_of(card);
  43. if (ret) {
  44. dev_err(dev, "Error parsing OF data\n");
  45. goto err;
  46. }
  47. apq8096_add_be_ops(card);
  48. ret = snd_soc_register_card(card);
  49. if (ret)
  50. goto err_card_register;
  51. return 0;
  52. err_card_register:
  53. kfree(card->dai_link);
  54. err:
  55. kfree(card);
  56. return ret;
  57. }
  58. static int apq8096_platform_remove(struct platform_device *pdev)
  59. {
  60. struct snd_soc_card *card = dev_get_drvdata(&pdev->dev);
  61. snd_soc_unregister_card(card);
  62. kfree(card->dai_link);
  63. kfree(card);
  64. return 0;
  65. }
  66. static const struct of_device_id msm_snd_apq8096_dt_match[] = {
  67. {.compatible = "qcom,apq8096-sndcard"},
  68. {}
  69. };
  70. MODULE_DEVICE_TABLE(of, msm_snd_apq8096_dt_match);
  71. static struct platform_driver msm_snd_apq8096_driver = {
  72. .probe = apq8096_platform_probe,
  73. .remove = apq8096_platform_remove,
  74. .driver = {
  75. .name = "msm-snd-apq8096",
  76. .of_match_table = msm_snd_apq8096_dt_match,
  77. },
  78. };
  79. module_platform_driver(msm_snd_apq8096_driver);
  80. MODULE_AUTHOR("Srinivas Kandagatla <srinivas.kandagatla@linaro.org");
  81. MODULE_DESCRIPTION("APQ8096 ASoC Machine Driver");
  82. MODULE_LICENSE("GPL v2");