trimslice.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * trimslice.c - TrimSlice machine ASoC driver
  3. *
  4. * Copyright (C) 2011 - CompuLab, Ltd.
  5. * Author: Mike Rapoport <mike@compulab.co.il>
  6. *
  7. * Based on code copyright/by:
  8. * Author: Stephen Warren <swarren@nvidia.com>
  9. * Copyright (C) 2010-2011 - NVIDIA, Inc.
  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
  13. * version 2 as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  23. * 02110-1301 USA
  24. *
  25. */
  26. #include <asm/mach-types.h>
  27. #include <linux/module.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/slab.h>
  30. #include <sound/core.h>
  31. #include <sound/jack.h>
  32. #include <sound/pcm.h>
  33. #include <sound/pcm_params.h>
  34. #include <sound/soc.h>
  35. #include "../codecs/tlv320aic23.h"
  36. #include "tegra_das.h"
  37. #include "tegra_i2s.h"
  38. #include "tegra_pcm.h"
  39. #include "tegra_asoc_utils.h"
  40. #define DRV_NAME "tegra-snd-trimslice"
  41. struct tegra_trimslice {
  42. struct tegra_asoc_utils_data util_data;
  43. };
  44. static int trimslice_asoc_hw_params(struct snd_pcm_substream *substream,
  45. struct snd_pcm_hw_params *params)
  46. {
  47. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  48. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  49. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  50. struct snd_soc_codec *codec = rtd->codec;
  51. struct snd_soc_card *card = codec->card;
  52. struct tegra_trimslice *trimslice = snd_soc_card_get_drvdata(card);
  53. int srate, mclk;
  54. int err;
  55. srate = params_rate(params);
  56. mclk = 128 * srate;
  57. err = tegra_asoc_utils_set_rate(&trimslice->util_data, srate, mclk);
  58. if (err < 0) {
  59. dev_err(card->dev, "Can't configure clocks\n");
  60. return err;
  61. }
  62. err = snd_soc_dai_set_fmt(codec_dai,
  63. SND_SOC_DAIFMT_I2S |
  64. SND_SOC_DAIFMT_NB_NF |
  65. SND_SOC_DAIFMT_CBS_CFS);
  66. if (err < 0) {
  67. dev_err(card->dev, "codec_dai fmt not set\n");
  68. return err;
  69. }
  70. err = snd_soc_dai_set_fmt(cpu_dai,
  71. SND_SOC_DAIFMT_I2S |
  72. SND_SOC_DAIFMT_NB_NF |
  73. SND_SOC_DAIFMT_CBS_CFS);
  74. if (err < 0) {
  75. dev_err(card->dev, "cpu_dai fmt not set\n");
  76. return err;
  77. }
  78. err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
  79. SND_SOC_CLOCK_IN);
  80. if (err < 0) {
  81. dev_err(card->dev, "codec_dai clock not set\n");
  82. return err;
  83. }
  84. return 0;
  85. }
  86. static struct snd_soc_ops trimslice_asoc_ops = {
  87. .hw_params = trimslice_asoc_hw_params,
  88. };
  89. static const struct snd_soc_dapm_widget trimslice_dapm_widgets[] = {
  90. SND_SOC_DAPM_HP("Line Out", NULL),
  91. SND_SOC_DAPM_LINE("Line In", NULL),
  92. };
  93. static const struct snd_soc_dapm_route trimslice_audio_map[] = {
  94. {"Line Out", NULL, "LOUT"},
  95. {"Line Out", NULL, "ROUT"},
  96. {"LLINEIN", NULL, "Line In"},
  97. {"RLINEIN", NULL, "Line In"},
  98. };
  99. static int trimslice_asoc_init(struct snd_soc_pcm_runtime *rtd)
  100. {
  101. struct snd_soc_codec *codec = rtd->codec;
  102. struct snd_soc_card *card = codec->card;
  103. struct snd_soc_dapm_context *dapm = &codec->dapm;
  104. int ret;
  105. ret = tegra_das_connect_dap_to_dac(TEGRA_DAS_DAP_ID_1,
  106. TEGRA_DAS_DAP_SEL_DAC1);
  107. if (ret) {
  108. dev_err(card->dev, "Can't set up DAS DAP connection\n");
  109. return ret;
  110. }
  111. ret = tegra_das_connect_dac_to_dap(TEGRA_DAS_DAC_ID_1,
  112. TEGRA_DAS_DAC_SEL_DAP1);
  113. if (ret) {
  114. dev_err(card->dev, "Can't set up DAS DAC connection\n");
  115. return ret;
  116. }
  117. snd_soc_dapm_nc_pin(dapm, "LHPOUT");
  118. snd_soc_dapm_nc_pin(dapm, "RHPOUT");
  119. snd_soc_dapm_nc_pin(dapm, "MICIN");
  120. return 0;
  121. }
  122. static struct snd_soc_dai_link trimslice_tlv320aic23_dai = {
  123. .name = "TLV320AIC23",
  124. .stream_name = "AIC23",
  125. .codec_name = "tlv320aic23-codec.2-001a",
  126. .platform_name = "tegra-pcm-audio",
  127. .cpu_dai_name = "tegra-i2s.0",
  128. .codec_dai_name = "tlv320aic23-hifi",
  129. .init = trimslice_asoc_init,
  130. .ops = &trimslice_asoc_ops,
  131. };
  132. static struct snd_soc_card snd_soc_trimslice = {
  133. .name = "tegra-trimslice",
  134. .dai_link = &trimslice_tlv320aic23_dai,
  135. .num_links = 1,
  136. .dapm_widgets = trimslice_dapm_widgets,
  137. .num_dapm_widgets = ARRAY_SIZE(trimslice_dapm_widgets),
  138. .dapm_routes = trimslice_audio_map,
  139. .num_dapm_routes = ARRAY_SIZE(trimslice_audio_map),
  140. };
  141. static __devinit int tegra_snd_trimslice_probe(struct platform_device *pdev)
  142. {
  143. struct snd_soc_card *card = &snd_soc_trimslice;
  144. struct tegra_trimslice *trimslice;
  145. int ret;
  146. trimslice = kzalloc(sizeof(struct tegra_trimslice), GFP_KERNEL);
  147. if (!trimslice) {
  148. dev_err(&pdev->dev, "Can't allocate tegra_trimslice\n");
  149. return -ENOMEM;
  150. }
  151. ret = tegra_asoc_utils_init(&trimslice->util_data, &pdev->dev);
  152. if (ret)
  153. goto err_free_trimslice;
  154. card->dev = &pdev->dev;
  155. platform_set_drvdata(pdev, card);
  156. snd_soc_card_set_drvdata(card, trimslice);
  157. ret = snd_soc_register_card(card);
  158. if (ret) {
  159. dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
  160. ret);
  161. goto err_fini_utils;
  162. }
  163. return 0;
  164. err_fini_utils:
  165. tegra_asoc_utils_fini(&trimslice->util_data);
  166. err_free_trimslice:
  167. kfree(trimslice);
  168. return ret;
  169. }
  170. static int __devexit tegra_snd_trimslice_remove(struct platform_device *pdev)
  171. {
  172. struct snd_soc_card *card = platform_get_drvdata(pdev);
  173. struct tegra_trimslice *trimslice = snd_soc_card_get_drvdata(card);
  174. snd_soc_unregister_card(card);
  175. tegra_asoc_utils_fini(&trimslice->util_data);
  176. kfree(trimslice);
  177. return 0;
  178. }
  179. static struct platform_driver tegra_snd_trimslice_driver = {
  180. .driver = {
  181. .name = DRV_NAME,
  182. .owner = THIS_MODULE,
  183. },
  184. .probe = tegra_snd_trimslice_probe,
  185. .remove = __devexit_p(tegra_snd_trimslice_remove),
  186. };
  187. static int __init snd_tegra_trimslice_init(void)
  188. {
  189. return platform_driver_register(&tegra_snd_trimslice_driver);
  190. }
  191. module_init(snd_tegra_trimslice_init);
  192. static void __exit snd_tegra_trimslice_exit(void)
  193. {
  194. platform_driver_unregister(&tegra_snd_trimslice_driver);
  195. }
  196. module_exit(snd_tegra_trimslice_exit);
  197. MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
  198. MODULE_DESCRIPTION("Trimslice machine ASoC driver");
  199. MODULE_LICENSE("GPL");
  200. MODULE_ALIAS("platform:" DRV_NAME);