skl_rt286.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*
  2. * Intel Skylake I2S Machine Driver
  3. *
  4. * Copyright (C) 2014-2015, Intel Corporation. All rights reserved.
  5. *
  6. * Modified from:
  7. * Intel Broadwell Wildcatpoint SST Audio
  8. *
  9. * Copyright (C) 2013, Intel Corporation. All rights reserved.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License version
  13. * 2 as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. */
  20. #include <linux/module.h>
  21. #include <linux/platform_device.h>
  22. #include <sound/core.h>
  23. #include <sound/pcm.h>
  24. #include <sound/soc.h>
  25. #include <sound/jack.h>
  26. #include <sound/pcm_params.h>
  27. #include "../../codecs/rt286.h"
  28. static struct snd_soc_jack skylake_headset;
  29. /* Headset jack detection DAPM pins */
  30. static struct snd_soc_jack_pin skylake_headset_pins[] = {
  31. {
  32. .pin = "Mic Jack",
  33. .mask = SND_JACK_MICROPHONE,
  34. },
  35. {
  36. .pin = "Headphone Jack",
  37. .mask = SND_JACK_HEADPHONE,
  38. },
  39. };
  40. static const struct snd_kcontrol_new skylake_controls[] = {
  41. SOC_DAPM_PIN_SWITCH("Speaker"),
  42. SOC_DAPM_PIN_SWITCH("Headphone Jack"),
  43. SOC_DAPM_PIN_SWITCH("Mic Jack"),
  44. };
  45. static const struct snd_soc_dapm_widget skylake_widgets[] = {
  46. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  47. SND_SOC_DAPM_SPK("Speaker", NULL),
  48. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  49. SND_SOC_DAPM_MIC("DMIC2", NULL),
  50. SND_SOC_DAPM_MIC("SoC DMIC", NULL),
  51. };
  52. static const struct snd_soc_dapm_route skylake_rt286_map[] = {
  53. /* speaker */
  54. {"Speaker", NULL, "SPOR"},
  55. {"Speaker", NULL, "SPOL"},
  56. /* HP jack connectors - unknown if we have jack deteck */
  57. {"Headphone Jack", NULL, "HPO Pin"},
  58. /* other jacks */
  59. {"MIC1", NULL, "Mic Jack"},
  60. /* digital mics */
  61. {"DMIC1 Pin", NULL, "DMIC2"},
  62. {"DMIC AIF", NULL, "SoC DMIC"},
  63. /* CODEC BE connections */
  64. { "AIF1 Playback", NULL, "ssp0 Tx"},
  65. { "ssp0 Tx", NULL, "codec0_out"},
  66. { "ssp0 Tx", NULL, "codec1_out"},
  67. { "codec0_in", NULL, "ssp0 Rx" },
  68. { "codec1_in", NULL, "ssp0 Rx" },
  69. { "ssp0 Rx", NULL, "AIF1 Capture" },
  70. { "dmic01_hifi", NULL, "DMIC01 Rx" },
  71. { "DMIC01 Rx", NULL, "Capture" },
  72. { "hif1", NULL, "iDisp Tx"},
  73. { "iDisp Tx", NULL, "iDisp_out"},
  74. };
  75. static int skylake_rt286_codec_init(struct snd_soc_pcm_runtime *rtd)
  76. {
  77. struct snd_soc_codec *codec = rtd->codec;
  78. int ret;
  79. ret = snd_soc_card_jack_new(rtd->card, "Headset",
  80. SND_JACK_HEADSET | SND_JACK_BTN_0,
  81. &skylake_headset,
  82. skylake_headset_pins, ARRAY_SIZE(skylake_headset_pins));
  83. if (ret)
  84. return ret;
  85. rt286_mic_detect(codec, &skylake_headset);
  86. return 0;
  87. }
  88. static int skylake_ssp0_fixup(struct snd_soc_pcm_runtime *rtd,
  89. struct snd_pcm_hw_params *params)
  90. {
  91. struct snd_interval *rate = hw_param_interval(params,
  92. SNDRV_PCM_HW_PARAM_RATE);
  93. struct snd_interval *channels = hw_param_interval(params,
  94. SNDRV_PCM_HW_PARAM_CHANNELS);
  95. /* The output is 48KHz, stereo, 16bits */
  96. rate->min = rate->max = 48000;
  97. channels->min = channels->max = 2;
  98. params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
  99. return 0;
  100. }
  101. static int skylake_rt286_hw_params(struct snd_pcm_substream *substream,
  102. struct snd_pcm_hw_params *params)
  103. {
  104. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  105. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  106. int ret;
  107. ret = snd_soc_dai_set_sysclk(codec_dai, RT286_SCLK_S_PLL, 24000000,
  108. SND_SOC_CLOCK_IN);
  109. if (ret < 0)
  110. dev_err(rtd->dev, "set codec sysclk failed: %d\n", ret);
  111. return ret;
  112. }
  113. static struct snd_soc_ops skylake_rt286_ops = {
  114. .hw_params = skylake_rt286_hw_params,
  115. };
  116. /* skylake digital audio interface glue - connects codec <--> CPU */
  117. static struct snd_soc_dai_link skylake_rt286_dais[] = {
  118. /* Front End DAI links */
  119. {
  120. .name = "Skl Audio Port",
  121. .stream_name = "Audio",
  122. .cpu_dai_name = "System Pin",
  123. .platform_name = "0000:00:1f.3",
  124. .nonatomic = 1,
  125. .dynamic = 1,
  126. .codec_name = "snd-soc-dummy",
  127. .codec_dai_name = "snd-soc-dummy-dai",
  128. .trigger = {
  129. SND_SOC_DPCM_TRIGGER_POST,
  130. SND_SOC_DPCM_TRIGGER_POST
  131. },
  132. .dpcm_playback = 1,
  133. },
  134. {
  135. .name = "Skl Audio Capture Port",
  136. .stream_name = "Audio Record",
  137. .cpu_dai_name = "System Pin",
  138. .platform_name = "0000:00:1f.3",
  139. .nonatomic = 1,
  140. .dynamic = 1,
  141. .codec_name = "snd-soc-dummy",
  142. .codec_dai_name = "snd-soc-dummy-dai",
  143. .trigger = {
  144. SND_SOC_DPCM_TRIGGER_POST,
  145. SND_SOC_DPCM_TRIGGER_POST
  146. },
  147. .dpcm_capture = 1,
  148. },
  149. {
  150. .name = "Skl Audio Reference cap",
  151. .stream_name = "refcap",
  152. .cpu_dai_name = "Reference Pin",
  153. .codec_name = "snd-soc-dummy",
  154. .codec_dai_name = "snd-soc-dummy-dai",
  155. .platform_name = "0000:00:1f.3",
  156. .init = NULL,
  157. .dpcm_capture = 1,
  158. .ignore_suspend = 1,
  159. .nonatomic = 1,
  160. .dynamic = 1,
  161. },
  162. /* Back End DAI links */
  163. {
  164. /* SSP0 - Codec */
  165. .name = "SSP0-Codec",
  166. .be_id = 0,
  167. .cpu_dai_name = "SSP0 Pin",
  168. .platform_name = "0000:00:1f.3",
  169. .no_pcm = 1,
  170. .codec_name = "i2c-INT343A:00",
  171. .codec_dai_name = "rt286-aif1",
  172. .init = skylake_rt286_codec_init,
  173. .dai_fmt = SND_SOC_DAIFMT_I2S |
  174. SND_SOC_DAIFMT_NB_NF |
  175. SND_SOC_DAIFMT_CBS_CFS,
  176. .ignore_suspend = 1,
  177. .ignore_pmdown_time = 1,
  178. .be_hw_params_fixup = skylake_ssp0_fixup,
  179. .ops = &skylake_rt286_ops,
  180. .dpcm_playback = 1,
  181. .dpcm_capture = 1,
  182. },
  183. {
  184. .name = "dmic01",
  185. .be_id = 1,
  186. .cpu_dai_name = "DMIC01 Pin",
  187. .codec_name = "dmic-codec",
  188. .codec_dai_name = "dmic-hifi",
  189. .platform_name = "0000:00:1f.3",
  190. .ignore_suspend = 1,
  191. .dpcm_capture = 1,
  192. .no_pcm = 1,
  193. },
  194. };
  195. /* skylake audio machine driver for SPT + RT286S */
  196. static struct snd_soc_card skylake_rt286 = {
  197. .name = "skylake-rt286",
  198. .owner = THIS_MODULE,
  199. .dai_link = skylake_rt286_dais,
  200. .num_links = ARRAY_SIZE(skylake_rt286_dais),
  201. .controls = skylake_controls,
  202. .num_controls = ARRAY_SIZE(skylake_controls),
  203. .dapm_widgets = skylake_widgets,
  204. .num_dapm_widgets = ARRAY_SIZE(skylake_widgets),
  205. .dapm_routes = skylake_rt286_map,
  206. .num_dapm_routes = ARRAY_SIZE(skylake_rt286_map),
  207. .fully_routed = true,
  208. };
  209. static int skylake_audio_probe(struct platform_device *pdev)
  210. {
  211. skylake_rt286.dev = &pdev->dev;
  212. return devm_snd_soc_register_card(&pdev->dev, &skylake_rt286);
  213. }
  214. static struct platform_driver skylake_audio = {
  215. .probe = skylake_audio_probe,
  216. .driver = {
  217. .name = "skl_alc286s_i2s",
  218. },
  219. };
  220. module_platform_driver(skylake_audio)
  221. /* Module information */
  222. MODULE_AUTHOR("Omair Mohammed Abdullah <omair.m.abdullah@intel.com>");
  223. MODULE_DESCRIPTION("Intel SST Audio for Skylake");
  224. MODULE_LICENSE("GPL v2");
  225. MODULE_ALIAS("platform:skl_alc286s_i2s");