snow.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * ASoC machine driver for Snow boards
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/of.h>
  16. #include <linux/of_device.h>
  17. #include <sound/soc.h>
  18. #include "i2s.h"
  19. #define FIN_PLL_RATE 24000000
  20. static struct snd_soc_dai_link snow_dai[] = {
  21. {
  22. .name = "Primary",
  23. .stream_name = "Primary",
  24. .codec_dai_name = "HiFi",
  25. .dai_fmt = SND_SOC_DAIFMT_I2S |
  26. SND_SOC_DAIFMT_NB_NF |
  27. SND_SOC_DAIFMT_CBS_CFS,
  28. },
  29. };
  30. static int snow_late_probe(struct snd_soc_card *card)
  31. {
  32. struct snd_soc_pcm_runtime *rtd;
  33. struct snd_soc_dai *codec_dai;
  34. struct snd_soc_dai *cpu_dai;
  35. int ret;
  36. rtd = snd_soc_get_pcm_runtime(card, card->dai_link[0].name);
  37. codec_dai = rtd->codec_dai;
  38. cpu_dai = rtd->cpu_dai;
  39. /* Set the MCLK rate for the codec */
  40. ret = snd_soc_dai_set_sysclk(codec_dai, 0,
  41. FIN_PLL_RATE, SND_SOC_CLOCK_IN);
  42. if (ret < 0)
  43. return ret;
  44. /* Select I2S Bus clock to set RCLK and BCLK */
  45. ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_RCLKSRC_0,
  46. 0, SND_SOC_CLOCK_IN);
  47. if (ret < 0)
  48. return ret;
  49. return 0;
  50. }
  51. static struct snd_soc_card snow_snd = {
  52. .name = "Snow-I2S",
  53. .owner = THIS_MODULE,
  54. .dai_link = snow_dai,
  55. .num_links = ARRAY_SIZE(snow_dai),
  56. .late_probe = snow_late_probe,
  57. };
  58. static int snow_probe(struct platform_device *pdev)
  59. {
  60. struct snd_soc_card *card = &snow_snd;
  61. struct device_node *i2s_node, *codec_node;
  62. int i, ret;
  63. i2s_node = of_parse_phandle(pdev->dev.of_node,
  64. "samsung,i2s-controller", 0);
  65. if (!i2s_node) {
  66. dev_err(&pdev->dev,
  67. "Property 'i2s-controller' missing or invalid\n");
  68. return -EINVAL;
  69. }
  70. codec_node = of_parse_phandle(pdev->dev.of_node,
  71. "samsung,audio-codec", 0);
  72. if (!codec_node) {
  73. dev_err(&pdev->dev,
  74. "Property 'audio-codec' missing or invalid\n");
  75. return -EINVAL;
  76. }
  77. for (i = 0; i < ARRAY_SIZE(snow_dai); i++) {
  78. snow_dai[i].codec_of_node = codec_node;
  79. snow_dai[i].cpu_of_node = i2s_node;
  80. snow_dai[i].platform_of_node = i2s_node;
  81. }
  82. card->dev = &pdev->dev;
  83. /* Update card-name if provided through DT, else use default name */
  84. snd_soc_of_parse_card_name(card, "samsung,model");
  85. ret = devm_snd_soc_register_card(&pdev->dev, card);
  86. if (ret) {
  87. dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
  88. return ret;
  89. }
  90. return ret;
  91. }
  92. static const struct of_device_id snow_of_match[] = {
  93. { .compatible = "google,snow-audio-max98090", },
  94. { .compatible = "google,snow-audio-max98091", },
  95. { .compatible = "google,snow-audio-max98095", },
  96. {},
  97. };
  98. MODULE_DEVICE_TABLE(of, snow_of_match);
  99. static struct platform_driver snow_driver = {
  100. .driver = {
  101. .name = "snow-audio",
  102. .pm = &snd_soc_pm_ops,
  103. .of_match_table = snow_of_match,
  104. },
  105. .probe = snow_probe,
  106. };
  107. module_platform_driver(snow_driver);
  108. MODULE_DESCRIPTION("ALSA SoC Audio machine driver for Snow");
  109. MODULE_LICENSE("GPL");