odroidx2_max98090.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * Copyright (C) 2014 Samsung Electronics Co., Ltd.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the
  6. * Free Software Foundation; either version 2 of the License, or (at your
  7. * option) any later version.
  8. */
  9. #include <linux/of.h>
  10. #include <linux/module.h>
  11. #include <sound/soc.h>
  12. #include <sound/pcm_params.h>
  13. #include "i2s.h"
  14. struct odroidx2_drv_data {
  15. const struct snd_soc_dapm_widget *dapm_widgets;
  16. unsigned int num_dapm_widgets;
  17. };
  18. /* The I2S CDCLK output clock frequency for the MAX98090 codec */
  19. #define MAX98090_MCLK 19200000
  20. static int odroidx2_late_probe(struct snd_soc_card *card)
  21. {
  22. struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
  23. struct snd_soc_dai *cpu_dai = card->rtd[0].cpu_dai;
  24. int ret;
  25. ret = snd_soc_dai_set_sysclk(codec_dai, 0, MAX98090_MCLK,
  26. SND_SOC_CLOCK_IN);
  27. if (ret < 0)
  28. return ret;
  29. /* Set the cpu DAI configuration in order to use CDCLK */
  30. return snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_CDCLK,
  31. 0, SND_SOC_CLOCK_OUT);
  32. }
  33. static const struct snd_soc_dapm_widget odroidx2_dapm_widgets[] = {
  34. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  35. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  36. SND_SOC_DAPM_MIC("DMIC", NULL),
  37. };
  38. static const struct snd_soc_dapm_widget odroidu3_dapm_widgets[] = {
  39. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  40. SND_SOC_DAPM_SPK("Speakers", NULL),
  41. };
  42. static struct snd_soc_dai_link odroidx2_dai[] = {
  43. {
  44. .name = "MAX98090",
  45. .stream_name = "MAX98090 PCM",
  46. .codec_dai_name = "HiFi",
  47. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  48. SND_SOC_DAIFMT_CBM_CFM,
  49. }
  50. };
  51. static struct snd_soc_card odroidx2 = {
  52. .owner = THIS_MODULE,
  53. .dai_link = odroidx2_dai,
  54. .num_links = ARRAY_SIZE(odroidx2_dai),
  55. .fully_routed = true,
  56. .late_probe = odroidx2_late_probe,
  57. };
  58. static const struct odroidx2_drv_data odroidx2_drvdata = {
  59. .dapm_widgets = odroidx2_dapm_widgets,
  60. .num_dapm_widgets = ARRAY_SIZE(odroidx2_dapm_widgets),
  61. };
  62. static const struct odroidx2_drv_data odroidu3_drvdata = {
  63. .dapm_widgets = odroidu3_dapm_widgets,
  64. .num_dapm_widgets = ARRAY_SIZE(odroidu3_dapm_widgets),
  65. };
  66. static const struct of_device_id odroidx2_audio_of_match[] = {
  67. {
  68. .compatible = "samsung,odroidx2-audio",
  69. .data = &odroidx2_drvdata,
  70. }, {
  71. .compatible = "samsung,odroidu3-audio",
  72. .data = &odroidu3_drvdata,
  73. },
  74. { },
  75. };
  76. MODULE_DEVICE_TABLE(of, odroidx2_audio_of_match);
  77. static int odroidx2_audio_probe(struct platform_device *pdev)
  78. {
  79. struct device_node *snd_node = pdev->dev.of_node;
  80. struct snd_soc_card *card = &odroidx2;
  81. struct device_node *i2s_node, *codec_node;
  82. struct odroidx2_drv_data *dd;
  83. const struct of_device_id *of_id;
  84. int ret;
  85. of_id = of_match_node(odroidx2_audio_of_match, snd_node);
  86. dd = (struct odroidx2_drv_data *)of_id->data;
  87. card->num_dapm_widgets = dd->num_dapm_widgets;
  88. card->dapm_widgets = dd->dapm_widgets;
  89. card->dev = &pdev->dev;
  90. ret = snd_soc_of_parse_card_name(card, "samsung,model");
  91. if (ret < 0)
  92. return ret;
  93. ret = snd_soc_of_parse_audio_routing(card, "samsung,audio-routing");
  94. if (ret < 0)
  95. return ret;
  96. codec_node = of_parse_phandle(snd_node, "samsung,audio-codec", 0);
  97. if (!codec_node) {
  98. dev_err(&pdev->dev,
  99. "Failed parsing samsung,i2s-codec property\n");
  100. return -EINVAL;
  101. }
  102. i2s_node = of_parse_phandle(snd_node, "samsung,i2s-controller", 0);
  103. if (!i2s_node) {
  104. dev_err(&pdev->dev,
  105. "Failed parsing samsung,i2s-controller property\n");
  106. ret = -EINVAL;
  107. goto err_put_codec_n;
  108. }
  109. odroidx2_dai[0].codec_of_node = codec_node;
  110. odroidx2_dai[0].cpu_of_node = i2s_node;
  111. odroidx2_dai[0].platform_of_node = i2s_node;
  112. ret = snd_soc_register_card(card);
  113. if (ret) {
  114. dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  115. ret);
  116. goto err_put_i2s_n;
  117. }
  118. return 0;
  119. err_put_i2s_n:
  120. of_node_put(i2s_node);
  121. err_put_codec_n:
  122. of_node_put(codec_node);
  123. return ret;
  124. }
  125. static int odroidx2_audio_remove(struct platform_device *pdev)
  126. {
  127. struct snd_soc_card *card = platform_get_drvdata(pdev);
  128. snd_soc_unregister_card(card);
  129. of_node_put((struct device_node *)odroidx2_dai[0].cpu_of_node);
  130. of_node_put((struct device_node *)odroidx2_dai[0].codec_of_node);
  131. return 0;
  132. }
  133. static struct platform_driver odroidx2_audio_driver = {
  134. .driver = {
  135. .name = "odroidx2-audio",
  136. .owner = THIS_MODULE,
  137. .of_match_table = odroidx2_audio_of_match,
  138. .pm = &snd_soc_pm_ops,
  139. },
  140. .probe = odroidx2_audio_probe,
  141. .remove = odroidx2_audio_remove,
  142. };
  143. module_platform_driver(odroidx2_audio_driver);
  144. MODULE_AUTHOR("Chen Zhen <zhen1.chen@samsung.com>");
  145. MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>");
  146. MODULE_DESCRIPTION("ALSA SoC Odroid X2/U3 Audio Support");
  147. MODULE_LICENSE("GPL v2");