haswell.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. * Intel Haswell Lynxpoint 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 "../common/sst-dsp.h"
  23. #include "../haswell/sst-haswell-ipc.h"
  24. #include "../../codecs/rt5640.h"
  25. /* Haswell ULT platforms have a Headphone and Mic jack */
  26. static const struct snd_soc_dapm_widget haswell_widgets[] = {
  27. SND_SOC_DAPM_HP("Headphones", NULL),
  28. SND_SOC_DAPM_MIC("Mic", NULL),
  29. };
  30. static const struct snd_soc_dapm_route haswell_rt5640_map[] = {
  31. {"Headphones", NULL, "HPOR"},
  32. {"Headphones", NULL, "HPOL"},
  33. {"IN2P", NULL, "Mic"},
  34. /* CODEC BE connections */
  35. {"SSP0 CODEC IN", NULL, "AIF1 Capture"},
  36. {"AIF1 Playback", NULL, "SSP0 CODEC OUT"},
  37. };
  38. static int haswell_ssp0_fixup(struct snd_soc_pcm_runtime *rtd,
  39. struct snd_pcm_hw_params *params)
  40. {
  41. struct snd_interval *rate = hw_param_interval(params,
  42. SNDRV_PCM_HW_PARAM_RATE);
  43. struct snd_interval *channels = hw_param_interval(params,
  44. SNDRV_PCM_HW_PARAM_CHANNELS);
  45. /* The ADSP will covert the FE rate to 48k, stereo */
  46. rate->min = rate->max = 48000;
  47. channels->min = channels->max = 2;
  48. /* set SSP0 to 16 bit */
  49. params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
  50. return 0;
  51. }
  52. static int haswell_rt5640_hw_params(struct snd_pcm_substream *substream,
  53. struct snd_pcm_hw_params *params)
  54. {
  55. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  56. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  57. int ret;
  58. ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_MCLK, 12288000,
  59. SND_SOC_CLOCK_IN);
  60. if (ret < 0) {
  61. dev_err(rtd->dev, "can't set codec sysclk configuration\n");
  62. return ret;
  63. }
  64. /* set correct codec filter for DAI format and clock config */
  65. snd_soc_update_bits(rtd->codec, 0x83, 0xffff, 0x8000);
  66. return ret;
  67. }
  68. static struct snd_soc_ops haswell_rt5640_ops = {
  69. .hw_params = haswell_rt5640_hw_params,
  70. };
  71. static int haswell_rtd_init(struct snd_soc_pcm_runtime *rtd)
  72. {
  73. struct sst_pdata *pdata = dev_get_platdata(rtd->platform->dev);
  74. struct sst_hsw *haswell = pdata->dsp;
  75. int ret;
  76. /* Set ADSP SSP port settings */
  77. ret = sst_hsw_device_set_config(haswell, SST_HSW_DEVICE_SSP_0,
  78. SST_HSW_DEVICE_MCLK_FREQ_24_MHZ,
  79. SST_HSW_DEVICE_CLOCK_MASTER, 9);
  80. if (ret < 0) {
  81. dev_err(rtd->dev, "failed to set device config\n");
  82. return ret;
  83. }
  84. return 0;
  85. }
  86. static struct snd_soc_dai_link haswell_rt5640_dais[] = {
  87. /* Front End DAI links */
  88. {
  89. .name = "System",
  90. .stream_name = "System Playback/Capture",
  91. .cpu_dai_name = "System Pin",
  92. .platform_name = "haswell-pcm-audio",
  93. .dynamic = 1,
  94. .codec_name = "snd-soc-dummy",
  95. .codec_dai_name = "snd-soc-dummy-dai",
  96. .init = haswell_rtd_init,
  97. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  98. .dpcm_playback = 1,
  99. .dpcm_capture = 1,
  100. },
  101. {
  102. .name = "Offload0",
  103. .stream_name = "Offload0 Playback",
  104. .cpu_dai_name = "Offload0 Pin",
  105. .platform_name = "haswell-pcm-audio",
  106. .dynamic = 1,
  107. .codec_name = "snd-soc-dummy",
  108. .codec_dai_name = "snd-soc-dummy-dai",
  109. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  110. .dpcm_playback = 1,
  111. },
  112. {
  113. .name = "Offload1",
  114. .stream_name = "Offload1 Playback",
  115. .cpu_dai_name = "Offload1 Pin",
  116. .platform_name = "haswell-pcm-audio",
  117. .dynamic = 1,
  118. .codec_name = "snd-soc-dummy",
  119. .codec_dai_name = "snd-soc-dummy-dai",
  120. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  121. .dpcm_playback = 1,
  122. },
  123. {
  124. .name = "Loopback",
  125. .stream_name = "Loopback",
  126. .cpu_dai_name = "Loopback Pin",
  127. .platform_name = "haswell-pcm-audio",
  128. .dynamic = 0,
  129. .codec_name = "snd-soc-dummy",
  130. .codec_dai_name = "snd-soc-dummy-dai",
  131. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  132. .dpcm_capture = 1,
  133. },
  134. /* Back End DAI links */
  135. {
  136. /* SSP0 - Codec */
  137. .name = "Codec",
  138. .id = 0,
  139. .cpu_dai_name = "snd-soc-dummy-dai",
  140. .platform_name = "snd-soc-dummy",
  141. .no_pcm = 1,
  142. .codec_name = "i2c-INT33CA:00",
  143. .codec_dai_name = "rt5640-aif1",
  144. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  145. SND_SOC_DAIFMT_CBS_CFS,
  146. .ignore_suspend = 1,
  147. .ignore_pmdown_time = 1,
  148. .be_hw_params_fixup = haswell_ssp0_fixup,
  149. .ops = &haswell_rt5640_ops,
  150. .dpcm_playback = 1,
  151. .dpcm_capture = 1,
  152. },
  153. };
  154. /* audio machine driver for Haswell Lynxpoint DSP + RT5640 */
  155. static struct snd_soc_card haswell_rt5640 = {
  156. .name = "haswell-rt5640",
  157. .owner = THIS_MODULE,
  158. .dai_link = haswell_rt5640_dais,
  159. .num_links = ARRAY_SIZE(haswell_rt5640_dais),
  160. .dapm_widgets = haswell_widgets,
  161. .num_dapm_widgets = ARRAY_SIZE(haswell_widgets),
  162. .dapm_routes = haswell_rt5640_map,
  163. .num_dapm_routes = ARRAY_SIZE(haswell_rt5640_map),
  164. .fully_routed = true,
  165. };
  166. static int haswell_audio_probe(struct platform_device *pdev)
  167. {
  168. haswell_rt5640.dev = &pdev->dev;
  169. return devm_snd_soc_register_card(&pdev->dev, &haswell_rt5640);
  170. }
  171. static struct platform_driver haswell_audio = {
  172. .probe = haswell_audio_probe,
  173. .driver = {
  174. .name = "haswell-audio",
  175. },
  176. };
  177. module_platform_driver(haswell_audio)
  178. /* Module information */
  179. MODULE_AUTHOR("Liam Girdwood, Xingchao Wang");
  180. MODULE_DESCRIPTION("Intel SST Audio for Haswell Lynxpoint");
  181. MODULE_LICENSE("GPL v2");
  182. MODULE_ALIAS("platform:haswell-audio");