byt-rt5640.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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/dmi.h>
  20. #include <linux/slab.h>
  21. #include <sound/pcm.h>
  22. #include <sound/pcm_params.h>
  23. #include <sound/soc.h>
  24. #include <sound/jack.h>
  25. #include "../../codecs/rt5640.h"
  26. #include "../common/sst-dsp.h"
  27. static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = {
  28. SND_SOC_DAPM_HP("Headphone", NULL),
  29. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  30. SND_SOC_DAPM_MIC("Internal Mic", NULL),
  31. SND_SOC_DAPM_SPK("Speaker", NULL),
  32. };
  33. static const struct snd_soc_dapm_route byt_rt5640_audio_map[] = {
  34. {"Headset Mic", NULL, "MICBIAS1"},
  35. {"IN2P", NULL, "Headset 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_soc_dapm_route byt_rt5640_intmic_dmic1_map[] = {
  44. {"DMIC1", NULL, "Internal Mic"},
  45. };
  46. static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic2_map[] = {
  47. {"DMIC2", NULL, "Internal Mic"},
  48. };
  49. static const struct snd_soc_dapm_route byt_rt5640_intmic_in1_map[] = {
  50. {"Internal Mic", NULL, "MICBIAS1"},
  51. {"IN1P", NULL, "Internal Mic"},
  52. };
  53. enum {
  54. BYT_RT5640_DMIC1_MAP,
  55. BYT_RT5640_DMIC2_MAP,
  56. BYT_RT5640_IN1_MAP,
  57. };
  58. #define BYT_RT5640_MAP(quirk) ((quirk) & 0xff)
  59. #define BYT_RT5640_DMIC_EN BIT(16)
  60. static unsigned long byt_rt5640_quirk = BYT_RT5640_DMIC1_MAP |
  61. BYT_RT5640_DMIC_EN;
  62. static const struct snd_kcontrol_new byt_rt5640_controls[] = {
  63. SOC_DAPM_PIN_SWITCH("Headphone"),
  64. SOC_DAPM_PIN_SWITCH("Headset Mic"),
  65. SOC_DAPM_PIN_SWITCH("Internal Mic"),
  66. SOC_DAPM_PIN_SWITCH("Speaker"),
  67. };
  68. static int byt_rt5640_hw_params(struct snd_pcm_substream *substream,
  69. struct snd_pcm_hw_params *params)
  70. {
  71. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  72. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  73. int ret;
  74. ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1,
  75. params_rate(params) * 256,
  76. SND_SOC_CLOCK_IN);
  77. if (ret < 0) {
  78. dev_err(codec_dai->dev, "can't set codec clock %d\n", ret);
  79. return ret;
  80. }
  81. ret = snd_soc_dai_set_pll(codec_dai, 0, RT5640_PLL1_S_BCLK1,
  82. params_rate(params) * 64,
  83. params_rate(params) * 256);
  84. if (ret < 0) {
  85. dev_err(codec_dai->dev, "can't set codec pll: %d\n", ret);
  86. return ret;
  87. }
  88. return 0;
  89. }
  90. static int byt_rt5640_quirk_cb(const struct dmi_system_id *id)
  91. {
  92. byt_rt5640_quirk = (unsigned long)id->driver_data;
  93. return 1;
  94. }
  95. static const struct dmi_system_id byt_rt5640_quirk_table[] = {
  96. {
  97. .callback = byt_rt5640_quirk_cb,
  98. .matches = {
  99. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  100. DMI_MATCH(DMI_PRODUCT_NAME, "T100TA"),
  101. },
  102. .driver_data = (unsigned long *)BYT_RT5640_IN1_MAP,
  103. },
  104. {
  105. .callback = byt_rt5640_quirk_cb,
  106. .matches = {
  107. DMI_MATCH(DMI_SYS_VENDOR, "DellInc."),
  108. DMI_MATCH(DMI_PRODUCT_NAME, "Venue 8 Pro 5830"),
  109. },
  110. .driver_data = (unsigned long *)(BYT_RT5640_DMIC2_MAP |
  111. BYT_RT5640_DMIC_EN),
  112. },
  113. {}
  114. };
  115. static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
  116. {
  117. int ret;
  118. struct snd_soc_codec *codec = runtime->codec;
  119. struct snd_soc_card *card = runtime->card;
  120. const struct snd_soc_dapm_route *custom_map;
  121. int num_routes;
  122. card->dapm.idle_bias_off = true;
  123. ret = snd_soc_add_card_controls(card, byt_rt5640_controls,
  124. ARRAY_SIZE(byt_rt5640_controls));
  125. if (ret) {
  126. dev_err(card->dev, "unable to add card controls\n");
  127. return ret;
  128. }
  129. dmi_check_system(byt_rt5640_quirk_table);
  130. switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
  131. case BYT_RT5640_IN1_MAP:
  132. custom_map = byt_rt5640_intmic_in1_map;
  133. num_routes = ARRAY_SIZE(byt_rt5640_intmic_in1_map);
  134. break;
  135. case BYT_RT5640_DMIC2_MAP:
  136. custom_map = byt_rt5640_intmic_dmic2_map;
  137. num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic2_map);
  138. break;
  139. default:
  140. custom_map = byt_rt5640_intmic_dmic1_map;
  141. num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic1_map);
  142. }
  143. ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
  144. if (ret)
  145. return ret;
  146. if (byt_rt5640_quirk & BYT_RT5640_DMIC_EN) {
  147. ret = rt5640_dmic_enable(codec, 0, 0);
  148. if (ret)
  149. return ret;
  150. }
  151. snd_soc_dapm_ignore_suspend(&card->dapm, "Headphone");
  152. snd_soc_dapm_ignore_suspend(&card->dapm, "Speaker");
  153. return ret;
  154. }
  155. static struct snd_soc_ops byt_rt5640_ops = {
  156. .hw_params = byt_rt5640_hw_params,
  157. };
  158. static struct snd_soc_dai_link byt_rt5640_dais[] = {
  159. {
  160. .name = "Baytrail Audio",
  161. .stream_name = "Audio",
  162. .cpu_dai_name = "baytrail-pcm-audio",
  163. .codec_dai_name = "rt5640-aif1",
  164. .codec_name = "i2c-10EC5640:00",
  165. .platform_name = "baytrail-pcm-audio",
  166. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  167. SND_SOC_DAIFMT_CBS_CFS,
  168. .init = byt_rt5640_init,
  169. .ops = &byt_rt5640_ops,
  170. },
  171. };
  172. static struct snd_soc_card byt_rt5640_card = {
  173. .name = "byt-rt5640",
  174. .owner = THIS_MODULE,
  175. .dai_link = byt_rt5640_dais,
  176. .num_links = ARRAY_SIZE(byt_rt5640_dais),
  177. .dapm_widgets = byt_rt5640_widgets,
  178. .num_dapm_widgets = ARRAY_SIZE(byt_rt5640_widgets),
  179. .dapm_routes = byt_rt5640_audio_map,
  180. .num_dapm_routes = ARRAY_SIZE(byt_rt5640_audio_map),
  181. .fully_routed = true,
  182. };
  183. static int byt_rt5640_probe(struct platform_device *pdev)
  184. {
  185. struct snd_soc_card *card = &byt_rt5640_card;
  186. card->dev = &pdev->dev;
  187. return devm_snd_soc_register_card(&pdev->dev, card);
  188. }
  189. static struct platform_driver byt_rt5640_audio = {
  190. .probe = byt_rt5640_probe,
  191. .driver = {
  192. .name = "byt-rt5640",
  193. .pm = &snd_soc_pm_ops,
  194. },
  195. };
  196. module_platform_driver(byt_rt5640_audio)
  197. MODULE_DESCRIPTION("ASoC Intel(R) Baytrail Machine driver");
  198. MODULE_AUTHOR("Omair Md Abdullah, Jarkko Nikula");
  199. MODULE_LICENSE("GPL v2");
  200. MODULE_ALIAS("platform:byt-rt5640");