snow.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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_dai *codec_dai = card->rtd[0].codec_dai;
  33. struct snd_soc_dai *cpu_dai = card->rtd[0].cpu_dai;
  34. int ret;
  35. /* Set the MCLK rate for the codec */
  36. ret = snd_soc_dai_set_sysclk(codec_dai, 0,
  37. FIN_PLL_RATE, SND_SOC_CLOCK_IN);
  38. if (ret < 0)
  39. return ret;
  40. /* Select I2S Bus clock to set RCLK and BCLK */
  41. ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_RCLKSRC_0,
  42. 0, SND_SOC_CLOCK_IN);
  43. if (ret < 0)
  44. return ret;
  45. return 0;
  46. }
  47. static struct snd_soc_card snow_snd = {
  48. .name = "Snow-I2S",
  49. .dai_link = snow_dai,
  50. .num_links = ARRAY_SIZE(snow_dai),
  51. .late_probe = snow_late_probe,
  52. };
  53. static int snow_probe(struct platform_device *pdev)
  54. {
  55. struct snd_soc_card *card = &snow_snd;
  56. struct device_node *i2s_node, *codec_node;
  57. int i, ret;
  58. i2s_node = of_parse_phandle(pdev->dev.of_node,
  59. "samsung,i2s-controller", 0);
  60. if (!i2s_node) {
  61. dev_err(&pdev->dev,
  62. "Property 'i2s-controller' missing or invalid\n");
  63. return -EINVAL;
  64. }
  65. codec_node = of_parse_phandle(pdev->dev.of_node,
  66. "samsung,audio-codec", 0);
  67. if (!codec_node) {
  68. dev_err(&pdev->dev,
  69. "Property 'audio-codec' missing or invalid\n");
  70. return -EINVAL;
  71. }
  72. for (i = 0; i < ARRAY_SIZE(snow_dai); i++) {
  73. snow_dai[i].codec_of_node = codec_node;
  74. snow_dai[i].cpu_of_node = i2s_node;
  75. snow_dai[i].platform_of_node = i2s_node;
  76. }
  77. card->dev = &pdev->dev;
  78. /* Update card-name if provided through DT, else use default name */
  79. snd_soc_of_parse_card_name(card, "samsung,model");
  80. ret = devm_snd_soc_register_card(&pdev->dev, card);
  81. if (ret) {
  82. dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
  83. return ret;
  84. }
  85. return ret;
  86. }
  87. static const struct of_device_id snow_of_match[] = {
  88. { .compatible = "google,snow-audio-max98090", },
  89. { .compatible = "google,snow-audio-max98091", },
  90. { .compatible = "google,snow-audio-max98095", },
  91. {},
  92. };
  93. MODULE_DEVICE_TABLE(of, snow_of_match);
  94. static struct platform_driver snow_driver = {
  95. .driver = {
  96. .name = "snow-audio",
  97. .owner = THIS_MODULE,
  98. .pm = &snd_soc_pm_ops,
  99. .of_match_table = snow_of_match,
  100. },
  101. .probe = snow_probe,
  102. };
  103. module_platform_driver(snow_driver);
  104. MODULE_DESCRIPTION("ALSA SoC Audio machine driver for Snow");
  105. MODULE_LICENSE("GPL");