broadwell.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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/jack.h>
  22. #include <sound/pcm_params.h>
  23. #include "../common/sst-dsp.h"
  24. #include "../haswell/sst-haswell-ipc.h"
  25. #include "../../codecs/rt286.h"
  26. static struct snd_soc_jack broadwell_headset;
  27. /* Headset jack detection DAPM pins */
  28. static struct snd_soc_jack_pin broadwell_headset_pins[] = {
  29. {
  30. .pin = "Mic Jack",
  31. .mask = SND_JACK_MICROPHONE,
  32. },
  33. {
  34. .pin = "Headphone Jack",
  35. .mask = SND_JACK_HEADPHONE,
  36. },
  37. };
  38. static const struct snd_kcontrol_new broadwell_controls[] = {
  39. SOC_DAPM_PIN_SWITCH("Speaker"),
  40. SOC_DAPM_PIN_SWITCH("Headphone Jack"),
  41. };
  42. static const struct snd_soc_dapm_widget broadwell_widgets[] = {
  43. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  44. SND_SOC_DAPM_SPK("Speaker", NULL),
  45. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  46. SND_SOC_DAPM_MIC("DMIC1", NULL),
  47. SND_SOC_DAPM_MIC("DMIC2", NULL),
  48. SND_SOC_DAPM_LINE("Line Jack", NULL),
  49. };
  50. static const struct snd_soc_dapm_route broadwell_rt286_map[] = {
  51. /* speaker */
  52. {"Speaker", NULL, "SPOR"},
  53. {"Speaker", NULL, "SPOL"},
  54. /* HP jack connectors - unknown if we have jack deteck */
  55. {"Headphone Jack", NULL, "HPO Pin"},
  56. /* other jacks */
  57. {"MIC1", NULL, "Mic Jack"},
  58. {"LINE1", NULL, "Line Jack"},
  59. /* digital mics */
  60. {"DMIC1 Pin", NULL, "DMIC1"},
  61. {"DMIC2 Pin", NULL, "DMIC2"},
  62. /* CODEC BE connections */
  63. {"SSP0 CODEC IN", NULL, "AIF1 Capture"},
  64. {"AIF1 Playback", NULL, "SSP0 CODEC OUT"},
  65. };
  66. static int broadwell_rt286_codec_init(struct snd_soc_pcm_runtime *rtd)
  67. {
  68. struct snd_soc_component *component = rtd->codec_dai->component;
  69. int ret = 0;
  70. ret = snd_soc_card_jack_new(rtd->card, "Headset",
  71. SND_JACK_HEADSET | SND_JACK_BTN_0, &broadwell_headset,
  72. broadwell_headset_pins, ARRAY_SIZE(broadwell_headset_pins));
  73. if (ret)
  74. return ret;
  75. rt286_mic_detect(component, &broadwell_headset);
  76. return 0;
  77. }
  78. static int broadwell_ssp0_fixup(struct snd_soc_pcm_runtime *rtd,
  79. struct snd_pcm_hw_params *params)
  80. {
  81. struct snd_interval *rate = hw_param_interval(params,
  82. SNDRV_PCM_HW_PARAM_RATE);
  83. struct snd_interval *channels = hw_param_interval(params,
  84. SNDRV_PCM_HW_PARAM_CHANNELS);
  85. /* The ADSP will covert the FE rate to 48k, stereo */
  86. rate->min = rate->max = 48000;
  87. channels->min = channels->max = 2;
  88. /* set SSP0 to 16 bit */
  89. params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
  90. return 0;
  91. }
  92. static int broadwell_rt286_hw_params(struct snd_pcm_substream *substream,
  93. struct snd_pcm_hw_params *params)
  94. {
  95. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  96. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  97. int ret;
  98. ret = snd_soc_dai_set_sysclk(codec_dai, RT286_SCLK_S_PLL, 24000000,
  99. SND_SOC_CLOCK_IN);
  100. if (ret < 0) {
  101. dev_err(rtd->dev, "can't set codec sysclk configuration\n");
  102. return ret;
  103. }
  104. return ret;
  105. }
  106. static const struct snd_soc_ops broadwell_rt286_ops = {
  107. .hw_params = broadwell_rt286_hw_params,
  108. };
  109. static int broadwell_rtd_init(struct snd_soc_pcm_runtime *rtd)
  110. {
  111. struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
  112. struct sst_pdata *pdata = dev_get_platdata(component->dev);
  113. struct sst_hsw *broadwell = pdata->dsp;
  114. int ret;
  115. /* Set ADSP SSP port settings */
  116. ret = sst_hsw_device_set_config(broadwell, SST_HSW_DEVICE_SSP_0,
  117. SST_HSW_DEVICE_MCLK_FREQ_24_MHZ,
  118. SST_HSW_DEVICE_CLOCK_MASTER, 9);
  119. if (ret < 0) {
  120. dev_err(rtd->dev, "error: failed to set device config\n");
  121. return ret;
  122. }
  123. return 0;
  124. }
  125. /* broadwell digital audio interface glue - connects codec <--> CPU */
  126. static struct snd_soc_dai_link broadwell_rt286_dais[] = {
  127. /* Front End DAI links */
  128. {
  129. .name = "System PCM",
  130. .stream_name = "System Playback/Capture",
  131. .cpu_dai_name = "System Pin",
  132. .platform_name = "haswell-pcm-audio",
  133. .dynamic = 1,
  134. .codec_name = "snd-soc-dummy",
  135. .codec_dai_name = "snd-soc-dummy-dai",
  136. .init = broadwell_rtd_init,
  137. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  138. .dpcm_playback = 1,
  139. .dpcm_capture = 1,
  140. },
  141. {
  142. .name = "Offload0",
  143. .stream_name = "Offload0 Playback",
  144. .cpu_dai_name = "Offload0 Pin",
  145. .platform_name = "haswell-pcm-audio",
  146. .dynamic = 1,
  147. .codec_name = "snd-soc-dummy",
  148. .codec_dai_name = "snd-soc-dummy-dai",
  149. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  150. .dpcm_playback = 1,
  151. },
  152. {
  153. .name = "Offload1",
  154. .stream_name = "Offload1 Playback",
  155. .cpu_dai_name = "Offload1 Pin",
  156. .platform_name = "haswell-pcm-audio",
  157. .dynamic = 1,
  158. .codec_name = "snd-soc-dummy",
  159. .codec_dai_name = "snd-soc-dummy-dai",
  160. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  161. .dpcm_playback = 1,
  162. },
  163. {
  164. .name = "Loopback PCM",
  165. .stream_name = "Loopback",
  166. .cpu_dai_name = "Loopback Pin",
  167. .platform_name = "haswell-pcm-audio",
  168. .dynamic = 1,
  169. .codec_name = "snd-soc-dummy",
  170. .codec_dai_name = "snd-soc-dummy-dai",
  171. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  172. .dpcm_capture = 1,
  173. },
  174. /* Back End DAI links */
  175. {
  176. /* SSP0 - Codec */
  177. .name = "Codec",
  178. .id = 0,
  179. .cpu_dai_name = "snd-soc-dummy-dai",
  180. .platform_name = "snd-soc-dummy",
  181. .no_pcm = 1,
  182. .codec_name = "i2c-INT343A:00",
  183. .codec_dai_name = "rt286-aif1",
  184. .init = broadwell_rt286_codec_init,
  185. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  186. SND_SOC_DAIFMT_CBS_CFS,
  187. .ignore_suspend = 1,
  188. .ignore_pmdown_time = 1,
  189. .be_hw_params_fixup = broadwell_ssp0_fixup,
  190. .ops = &broadwell_rt286_ops,
  191. .dpcm_playback = 1,
  192. .dpcm_capture = 1,
  193. },
  194. };
  195. static int broadwell_suspend(struct snd_soc_card *card){
  196. struct snd_soc_component *component;
  197. list_for_each_entry(component, &card->component_dev_list, card_list) {
  198. if (!strcmp(component->name, "i2c-INT343A:00")) {
  199. dev_dbg(component->dev, "disabling jack detect before going to suspend.\n");
  200. rt286_mic_detect(component, NULL);
  201. break;
  202. }
  203. }
  204. return 0;
  205. }
  206. static int broadwell_resume(struct snd_soc_card *card){
  207. struct snd_soc_component *component;
  208. list_for_each_entry(component, &card->component_dev_list, card_list) {
  209. if (!strcmp(component->name, "i2c-INT343A:00")) {
  210. dev_dbg(component->dev, "enabling jack detect for resume.\n");
  211. rt286_mic_detect(component, &broadwell_headset);
  212. break;
  213. }
  214. }
  215. return 0;
  216. }
  217. /* broadwell audio machine driver for WPT + RT286S */
  218. static struct snd_soc_card broadwell_rt286 = {
  219. .name = "broadwell-rt286",
  220. .owner = THIS_MODULE,
  221. .dai_link = broadwell_rt286_dais,
  222. .num_links = ARRAY_SIZE(broadwell_rt286_dais),
  223. .controls = broadwell_controls,
  224. .num_controls = ARRAY_SIZE(broadwell_controls),
  225. .dapm_widgets = broadwell_widgets,
  226. .num_dapm_widgets = ARRAY_SIZE(broadwell_widgets),
  227. .dapm_routes = broadwell_rt286_map,
  228. .num_dapm_routes = ARRAY_SIZE(broadwell_rt286_map),
  229. .fully_routed = true,
  230. .suspend_pre = broadwell_suspend,
  231. .resume_post = broadwell_resume,
  232. };
  233. static int broadwell_audio_probe(struct platform_device *pdev)
  234. {
  235. broadwell_rt286.dev = &pdev->dev;
  236. return devm_snd_soc_register_card(&pdev->dev, &broadwell_rt286);
  237. }
  238. static struct platform_driver broadwell_audio = {
  239. .probe = broadwell_audio_probe,
  240. .driver = {
  241. .name = "broadwell-audio",
  242. },
  243. };
  244. module_platform_driver(broadwell_audio)
  245. /* Module information */
  246. MODULE_AUTHOR("Liam Girdwood, Xingchao Wang");
  247. MODULE_DESCRIPTION("Intel SST Audio for WPT/Broadwell");
  248. MODULE_LICENSE("GPL v2");
  249. MODULE_ALIAS("platform:broadwell-audio");