broadwell.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*
  2. * Intel Broadwell Wildcatpoint SST Audio
  3. *
  4. * Copyright (C) 2013, Intel Corporation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License version
  8. * 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. */
  16. #include <linux/module.h>
  17. #include <linux/platform_device.h>
  18. #include <sound/core.h>
  19. #include <sound/pcm.h>
  20. #include <sound/soc.h>
  21. #include <sound/pcm_params.h>
  22. #include "sst-dsp.h"
  23. #include "sst-haswell-ipc.h"
  24. #include "../codecs/rt286.h"
  25. static const struct snd_soc_dapm_widget broadwell_widgets[] = {
  26. SND_SOC_DAPM_HP("Headphones", NULL),
  27. SND_SOC_DAPM_SPK("Speaker", NULL),
  28. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  29. SND_SOC_DAPM_MIC("DMIC1", NULL),
  30. SND_SOC_DAPM_MIC("DMIC2", NULL),
  31. SND_SOC_DAPM_LINE("Line Jack", NULL),
  32. };
  33. static const struct snd_soc_dapm_route broadwell_rt286_map[] = {
  34. /* speaker */
  35. {"Speaker", NULL, "SPOR"},
  36. {"Speaker", NULL, "SPOL"},
  37. /* HP jack connectors - unknown if we have jack deteck */
  38. {"Headphones", NULL, "HPO Pin"},
  39. /* other jacks */
  40. {"MIC1", NULL, "Mic Jack"},
  41. {"LINE1", NULL, "Line Jack"},
  42. /* digital mics */
  43. {"DMIC1 Pin", NULL, "DMIC1"},
  44. {"DMIC2 Pin", NULL, "DMIC2"},
  45. /* CODEC BE connections */
  46. {"SSP0 CODEC IN", NULL, "AIF1 Capture"},
  47. {"AIF1 Playback", NULL, "SSP0 CODEC OUT"},
  48. };
  49. static int broadwell_ssp0_fixup(struct snd_soc_pcm_runtime *rtd,
  50. struct snd_pcm_hw_params *params)
  51. {
  52. struct snd_interval *rate = hw_param_interval(params,
  53. SNDRV_PCM_HW_PARAM_RATE);
  54. struct snd_interval *channels = hw_param_interval(params,
  55. SNDRV_PCM_HW_PARAM_CHANNELS);
  56. /* The ADSP will covert the FE rate to 48k, stereo */
  57. rate->min = rate->max = 48000;
  58. channels->min = channels->max = 2;
  59. /* set SSP0 to 16 bit */
  60. snd_mask_set(&params->masks[SNDRV_PCM_HW_PARAM_FORMAT -
  61. SNDRV_PCM_HW_PARAM_FIRST_MASK],
  62. SNDRV_PCM_FORMAT_S16_LE);
  63. return 0;
  64. }
  65. static int broadwell_rt286_hw_params(struct snd_pcm_substream *substream,
  66. struct snd_pcm_hw_params *params)
  67. {
  68. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  69. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  70. int ret;
  71. ret = snd_soc_dai_set_sysclk(codec_dai, RT286_SCLK_S_PLL, 24000000,
  72. SND_SOC_CLOCK_IN);
  73. if (ret < 0) {
  74. dev_err(rtd->dev, "can't set codec sysclk configuration\n");
  75. return ret;
  76. }
  77. return ret;
  78. }
  79. static struct snd_soc_ops broadwell_rt286_ops = {
  80. .hw_params = broadwell_rt286_hw_params,
  81. };
  82. static int broadwell_rtd_init(struct snd_soc_pcm_runtime *rtd)
  83. {
  84. struct snd_soc_codec *codec = rtd->codec;
  85. struct snd_soc_dapm_context *dapm = &codec->dapm;
  86. struct sst_pdata *pdata = dev_get_platdata(rtd->platform->dev);
  87. struct sst_hsw *broadwell = pdata->dsp;
  88. int ret;
  89. /* Set ADSP SSP port settings */
  90. ret = sst_hsw_device_set_config(broadwell, SST_HSW_DEVICE_SSP_0,
  91. SST_HSW_DEVICE_MCLK_FREQ_24_MHZ,
  92. SST_HSW_DEVICE_CLOCK_MASTER, 9);
  93. if (ret < 0) {
  94. dev_err(rtd->dev, "error: failed to set device config\n");
  95. return ret;
  96. }
  97. /* always connected - check HP for jack detect */
  98. snd_soc_dapm_enable_pin(dapm, "Headphones");
  99. snd_soc_dapm_enable_pin(dapm, "Speaker");
  100. snd_soc_dapm_enable_pin(dapm, "Mic Jack");
  101. snd_soc_dapm_enable_pin(dapm, "Line Jack");
  102. snd_soc_dapm_enable_pin(dapm, "DMIC1");
  103. snd_soc_dapm_enable_pin(dapm, "DMIC2");
  104. return 0;
  105. }
  106. /* broadwell digital audio interface glue - connects codec <--> CPU */
  107. static struct snd_soc_dai_link broadwell_rt286_dais[] = {
  108. /* Front End DAI links */
  109. {
  110. .name = "System PCM",
  111. .stream_name = "System Playback",
  112. .cpu_dai_name = "System Pin",
  113. .platform_name = "haswell-pcm-audio",
  114. .dynamic = 1,
  115. .codec_name = "snd-soc-dummy",
  116. .codec_dai_name = "snd-soc-dummy-dai",
  117. .init = broadwell_rtd_init,
  118. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  119. .dpcm_playback = 1,
  120. },
  121. {
  122. .name = "Offload0",
  123. .stream_name = "Offload0 Playback",
  124. .cpu_dai_name = "Offload0 Pin",
  125. .platform_name = "haswell-pcm-audio",
  126. .dynamic = 1,
  127. .codec_name = "snd-soc-dummy",
  128. .codec_dai_name = "snd-soc-dummy-dai",
  129. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  130. .dpcm_playback = 1,
  131. },
  132. {
  133. .name = "Offload1",
  134. .stream_name = "Offload1 Playback",
  135. .cpu_dai_name = "Offload1 Pin",
  136. .platform_name = "haswell-pcm-audio",
  137. .dynamic = 1,
  138. .codec_name = "snd-soc-dummy",
  139. .codec_dai_name = "snd-soc-dummy-dai",
  140. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  141. .dpcm_playback = 1,
  142. },
  143. {
  144. .name = "Loopback PCM",
  145. .stream_name = "Loopback",
  146. .cpu_dai_name = "Loopback Pin",
  147. .platform_name = "haswell-pcm-audio",
  148. .dynamic = 0,
  149. .codec_name = "snd-soc-dummy",
  150. .codec_dai_name = "snd-soc-dummy-dai",
  151. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  152. .dpcm_capture = 1,
  153. },
  154. {
  155. .name = "Capture PCM",
  156. .stream_name = "Capture",
  157. .cpu_dai_name = "Capture Pin",
  158. .platform_name = "haswell-pcm-audio",
  159. .dynamic = 1,
  160. .codec_name = "snd-soc-dummy",
  161. .codec_dai_name = "snd-soc-dummy-dai",
  162. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  163. .dpcm_capture = 1,
  164. },
  165. /* Back End DAI links */
  166. {
  167. /* SSP0 - Codec */
  168. .name = "Codec",
  169. .be_id = 0,
  170. .cpu_dai_name = "snd-soc-dummy-dai",
  171. .platform_name = "snd-soc-dummy",
  172. .no_pcm = 1,
  173. .codec_name = "i2c-INT343A:00",
  174. .codec_dai_name = "rt286-aif1",
  175. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  176. SND_SOC_DAIFMT_CBS_CFS,
  177. .ignore_suspend = 1,
  178. .ignore_pmdown_time = 1,
  179. .be_hw_params_fixup = broadwell_ssp0_fixup,
  180. .ops = &broadwell_rt286_ops,
  181. .dpcm_playback = 1,
  182. .dpcm_capture = 1,
  183. },
  184. };
  185. /* broadwell audio machine driver for WPT + RT286S */
  186. static struct snd_soc_card broadwell_rt286 = {
  187. .name = "broadwell-rt286",
  188. .owner = THIS_MODULE,
  189. .dai_link = broadwell_rt286_dais,
  190. .num_links = ARRAY_SIZE(broadwell_rt286_dais),
  191. .dapm_widgets = broadwell_widgets,
  192. .num_dapm_widgets = ARRAY_SIZE(broadwell_widgets),
  193. .dapm_routes = broadwell_rt286_map,
  194. .num_dapm_routes = ARRAY_SIZE(broadwell_rt286_map),
  195. .fully_routed = true,
  196. };
  197. static int broadwell_audio_probe(struct platform_device *pdev)
  198. {
  199. broadwell_rt286.dev = &pdev->dev;
  200. return snd_soc_register_card(&broadwell_rt286);
  201. }
  202. static int broadwell_audio_remove(struct platform_device *pdev)
  203. {
  204. snd_soc_unregister_card(&broadwell_rt286);
  205. return 0;
  206. }
  207. static struct platform_driver broadwell_audio = {
  208. .probe = broadwell_audio_probe,
  209. .remove = broadwell_audio_remove,
  210. .driver = {
  211. .name = "broadwell-audio",
  212. .owner = THIS_MODULE,
  213. },
  214. };
  215. module_platform_driver(broadwell_audio)
  216. /* Module information */
  217. MODULE_AUTHOR("Liam Girdwood, Xingchao Wang");
  218. MODULE_DESCRIPTION("Intel SST Audio for WPT/Broadwell");
  219. MODULE_LICENSE("GPL v2");
  220. MODULE_ALIAS("platform:broadwell-audio");