byt-rt5640.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Intel Baytrail SST RT5640 machine driver
  3. * Copyright (c) 2014, Intel Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. */
  14. #include <linux/init.h>
  15. #include <linux/module.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/acpi.h>
  18. #include <linux/device.h>
  19. #include <linux/slab.h>
  20. #include <sound/pcm.h>
  21. #include <sound/pcm_params.h>
  22. #include <sound/soc.h>
  23. #include <sound/jack.h>
  24. #include "../codecs/rt5640.h"
  25. #include "sst-dsp.h"
  26. static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = {
  27. SND_SOC_DAPM_HP("Headphone", NULL),
  28. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  29. SND_SOC_DAPM_MIC("Internal Mic", NULL),
  30. SND_SOC_DAPM_SPK("Speaker", NULL),
  31. };
  32. static const struct snd_soc_dapm_route byt_rt5640_audio_map[] = {
  33. {"IN2P", NULL, "Headset Mic"},
  34. {"IN2N", NULL, "Headset Mic"},
  35. {"DMIC1", NULL, "Internal Mic"},
  36. {"Headphone", NULL, "HPOL"},
  37. {"Headphone", NULL, "HPOR"},
  38. {"Speaker", NULL, "SPOLP"},
  39. {"Speaker", NULL, "SPOLN"},
  40. {"Speaker", NULL, "SPORP"},
  41. {"Speaker", NULL, "SPORN"},
  42. };
  43. static const struct snd_kcontrol_new byt_rt5640_controls[] = {
  44. SOC_DAPM_PIN_SWITCH("Headphone"),
  45. SOC_DAPM_PIN_SWITCH("Headset Mic"),
  46. SOC_DAPM_PIN_SWITCH("Internal Mic"),
  47. SOC_DAPM_PIN_SWITCH("Speaker"),
  48. };
  49. static int byt_rt5640_hw_params(struct snd_pcm_substream *substream,
  50. struct snd_pcm_hw_params *params)
  51. {
  52. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  53. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  54. int ret;
  55. ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1,
  56. params_rate(params) * 256,
  57. SND_SOC_CLOCK_IN);
  58. if (ret < 0) {
  59. dev_err(codec_dai->dev, "can't set codec clock %d\n", ret);
  60. return ret;
  61. }
  62. ret = snd_soc_dai_set_pll(codec_dai, 0, RT5640_PLL1_S_BCLK1,
  63. params_rate(params) * 64,
  64. params_rate(params) * 256);
  65. if (ret < 0) {
  66. dev_err(codec_dai->dev, "can't set codec pll: %d\n", ret);
  67. return ret;
  68. }
  69. return 0;
  70. }
  71. static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
  72. {
  73. int ret;
  74. struct snd_soc_codec *codec = runtime->codec;
  75. struct snd_soc_dapm_context *dapm = &codec->dapm;
  76. struct snd_soc_card *card = runtime->card;
  77. card->dapm.idle_bias_off = true;
  78. ret = snd_soc_add_card_controls(card, byt_rt5640_controls,
  79. ARRAY_SIZE(byt_rt5640_controls));
  80. if (ret) {
  81. dev_err(card->dev, "unable to add card controls\n");
  82. return ret;
  83. }
  84. snd_soc_dapm_ignore_suspend(dapm, "HPOL");
  85. snd_soc_dapm_ignore_suspend(dapm, "HPOR");
  86. snd_soc_dapm_ignore_suspend(dapm, "SPOLP");
  87. snd_soc_dapm_ignore_suspend(dapm, "SPOLN");
  88. snd_soc_dapm_ignore_suspend(dapm, "SPORP");
  89. snd_soc_dapm_ignore_suspend(dapm, "SPORN");
  90. return ret;
  91. }
  92. static struct snd_soc_ops byt_rt5640_ops = {
  93. .hw_params = byt_rt5640_hw_params,
  94. };
  95. static struct snd_soc_dai_link byt_rt5640_dais[] = {
  96. {
  97. .name = "Baytrail Audio",
  98. .stream_name = "Audio",
  99. .cpu_dai_name = "baytrail-pcm-audio",
  100. .codec_dai_name = "rt5640-aif1",
  101. .codec_name = "i2c-10EC5640:00",
  102. .platform_name = "baytrail-pcm-audio",
  103. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  104. SND_SOC_DAIFMT_CBS_CFS,
  105. .init = byt_rt5640_init,
  106. .ops = &byt_rt5640_ops,
  107. },
  108. };
  109. static struct snd_soc_card byt_rt5640_card = {
  110. .name = "byt-rt5640",
  111. .dai_link = byt_rt5640_dais,
  112. .num_links = ARRAY_SIZE(byt_rt5640_dais),
  113. .dapm_widgets = byt_rt5640_widgets,
  114. .num_dapm_widgets = ARRAY_SIZE(byt_rt5640_widgets),
  115. .dapm_routes = byt_rt5640_audio_map,
  116. .num_dapm_routes = ARRAY_SIZE(byt_rt5640_audio_map),
  117. };
  118. static int byt_rt5640_probe(struct platform_device *pdev)
  119. {
  120. struct snd_soc_card *card = &byt_rt5640_card;
  121. card->dev = &pdev->dev;
  122. return devm_snd_soc_register_card(&pdev->dev, card);
  123. }
  124. static struct platform_driver byt_rt5640_audio = {
  125. .probe = byt_rt5640_probe,
  126. .driver = {
  127. .name = "byt-rt5640",
  128. .owner = THIS_MODULE,
  129. .pm = &snd_soc_pm_ops,
  130. },
  131. };
  132. module_platform_driver(byt_rt5640_audio)
  133. MODULE_DESCRIPTION("ASoC Intel(R) Baytrail Machine driver");
  134. MODULE_AUTHOR("Omair Md Abdullah, Jarkko Nikula");
  135. MODULE_LICENSE("GPL v2");
  136. MODULE_ALIAS("platform:byt-rt5640");