haswell.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 "sst-dsp.h"
  23. #include "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. snd_mask_set(&params->masks[SNDRV_PCM_HW_PARAM_FORMAT -
  50. SNDRV_PCM_HW_PARAM_FIRST_MASK],
  51. SNDRV_PCM_FORMAT_S16_LE);
  52. return 0;
  53. }
  54. static int haswell_rt5640_hw_params(struct snd_pcm_substream *substream,
  55. struct snd_pcm_hw_params *params)
  56. {
  57. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  58. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  59. int ret;
  60. ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_MCLK, 12288000,
  61. SND_SOC_CLOCK_IN);
  62. if (ret < 0) {
  63. dev_err(rtd->dev, "can't set codec sysclk configuration\n");
  64. return ret;
  65. }
  66. /* set correct codec filter for DAI format and clock config */
  67. snd_soc_update_bits(rtd->codec, 0x83, 0xffff, 0x8000);
  68. return ret;
  69. }
  70. static struct snd_soc_ops haswell_rt5640_ops = {
  71. .hw_params = haswell_rt5640_hw_params,
  72. };
  73. static int haswell_rtd_init(struct snd_soc_pcm_runtime *rtd)
  74. {
  75. struct sst_pdata *pdata = dev_get_platdata(rtd->platform->dev);
  76. struct sst_hsw *haswell = pdata->dsp;
  77. int ret;
  78. /* Set ADSP SSP port settings */
  79. ret = sst_hsw_device_set_config(haswell, SST_HSW_DEVICE_SSP_0,
  80. SST_HSW_DEVICE_MCLK_FREQ_24_MHZ,
  81. SST_HSW_DEVICE_CLOCK_MASTER, 9);
  82. if (ret < 0) {
  83. dev_err(rtd->dev, "failed to set device config\n");
  84. return ret;
  85. }
  86. return 0;
  87. }
  88. static struct snd_soc_dai_link haswell_rt5640_dais[] = {
  89. /* Front End DAI links */
  90. {
  91. .name = "System",
  92. .stream_name = "System Playback",
  93. .cpu_dai_name = "System Pin",
  94. .platform_name = "haswell-pcm-audio",
  95. .dynamic = 1,
  96. .codec_name = "snd-soc-dummy",
  97. .codec_dai_name = "snd-soc-dummy-dai",
  98. .init = haswell_rtd_init,
  99. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  100. .dpcm_playback = 1,
  101. },
  102. {
  103. .name = "Offload0",
  104. .stream_name = "Offload0 Playback",
  105. .cpu_dai_name = "Offload0 Pin",
  106. .platform_name = "haswell-pcm-audio",
  107. .dynamic = 1,
  108. .codec_name = "snd-soc-dummy",
  109. .codec_dai_name = "snd-soc-dummy-dai",
  110. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  111. .dpcm_playback = 1,
  112. },
  113. {
  114. .name = "Offload1",
  115. .stream_name = "Offload1 Playback",
  116. .cpu_dai_name = "Offload1 Pin",
  117. .platform_name = "haswell-pcm-audio",
  118. .dynamic = 1,
  119. .codec_name = "snd-soc-dummy",
  120. .codec_dai_name = "snd-soc-dummy-dai",
  121. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  122. .dpcm_playback = 1,
  123. },
  124. {
  125. .name = "Loopback",
  126. .stream_name = "Loopback",
  127. .cpu_dai_name = "Loopback Pin",
  128. .platform_name = "haswell-pcm-audio",
  129. .dynamic = 0,
  130. .codec_name = "snd-soc-dummy",
  131. .codec_dai_name = "snd-soc-dummy-dai",
  132. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  133. .dpcm_capture = 1,
  134. },
  135. {
  136. .name = "Capture",
  137. .stream_name = "Capture",
  138. .cpu_dai_name = "Capture Pin",
  139. .platform_name = "haswell-pcm-audio",
  140. .dynamic = 1,
  141. .codec_name = "snd-soc-dummy",
  142. .codec_dai_name = "snd-soc-dummy-dai",
  143. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  144. .dpcm_capture = 1,
  145. },
  146. /* Back End DAI links */
  147. {
  148. /* SSP0 - Codec */
  149. .name = "Codec",
  150. .be_id = 0,
  151. .cpu_dai_name = "snd-soc-dummy-dai",
  152. .platform_name = "snd-soc-dummy",
  153. .no_pcm = 1,
  154. .codec_name = "i2c-INT33CA:00",
  155. .codec_dai_name = "rt5640-aif1",
  156. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  157. SND_SOC_DAIFMT_CBS_CFS,
  158. .ignore_suspend = 1,
  159. .ignore_pmdown_time = 1,
  160. .be_hw_params_fixup = haswell_ssp0_fixup,
  161. .ops = &haswell_rt5640_ops,
  162. .dpcm_playback = 1,
  163. .dpcm_capture = 1,
  164. },
  165. };
  166. /* audio machine driver for Haswell Lynxpoint DSP + RT5640 */
  167. static struct snd_soc_card haswell_rt5640 = {
  168. .name = "haswell-rt5640",
  169. .owner = THIS_MODULE,
  170. .dai_link = haswell_rt5640_dais,
  171. .num_links = ARRAY_SIZE(haswell_rt5640_dais),
  172. .dapm_widgets = haswell_widgets,
  173. .num_dapm_widgets = ARRAY_SIZE(haswell_widgets),
  174. .dapm_routes = haswell_rt5640_map,
  175. .num_dapm_routes = ARRAY_SIZE(haswell_rt5640_map),
  176. .fully_routed = true,
  177. };
  178. static int haswell_audio_probe(struct platform_device *pdev)
  179. {
  180. haswell_rt5640.dev = &pdev->dev;
  181. return devm_snd_soc_register_card(&pdev->dev, &haswell_rt5640);
  182. }
  183. static struct platform_driver haswell_audio = {
  184. .probe = haswell_audio_probe,
  185. .driver = {
  186. .name = "haswell-audio",
  187. .owner = THIS_MODULE,
  188. },
  189. };
  190. module_platform_driver(haswell_audio)
  191. /* Module information */
  192. MODULE_AUTHOR("Liam Girdwood, Xingchao Wang");
  193. MODULE_DESCRIPTION("Intel SST Audio for Haswell Lynxpoint");
  194. MODULE_LICENSE("GPL v2");
  195. MODULE_ALIAS("platform:haswell-audio");