trimslice.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 struct snd_soc_dai_link trimslice_tlv320aic23_dai = {
  100. .name = "TLV320AIC23",
  101. .stream_name = "AIC23",
  102. .codec_name = "tlv320aic23-codec.2-001a",
  103. .platform_name = "tegra-pcm-audio",
  104. .cpu_dai_name = "tegra-i2s.0",
  105. .codec_dai_name = "tlv320aic23-hifi",
  106. .ops = &trimslice_asoc_ops,
  107. };
  108. static struct snd_soc_card snd_soc_trimslice = {
  109. .name = "tegra-trimslice",
  110. .owner = THIS_MODULE,
  111. .dai_link = &trimslice_tlv320aic23_dai,
  112. .num_links = 1,
  113. .dapm_widgets = trimslice_dapm_widgets,
  114. .num_dapm_widgets = ARRAY_SIZE(trimslice_dapm_widgets),
  115. .dapm_routes = trimslice_audio_map,
  116. .num_dapm_routes = ARRAY_SIZE(trimslice_audio_map),
  117. .fully_routed = true,
  118. };
  119. static __devinit int tegra_snd_trimslice_probe(struct platform_device *pdev)
  120. {
  121. struct snd_soc_card *card = &snd_soc_trimslice;
  122. struct tegra_trimslice *trimslice;
  123. int ret;
  124. trimslice = devm_kzalloc(&pdev->dev, sizeof(struct tegra_trimslice),
  125. GFP_KERNEL);
  126. if (!trimslice) {
  127. dev_err(&pdev->dev, "Can't allocate tegra_trimslice\n");
  128. ret = -ENOMEM;
  129. goto err;
  130. }
  131. ret = tegra_asoc_utils_init(&trimslice->util_data, &pdev->dev);
  132. if (ret)
  133. goto err;
  134. card->dev = &pdev->dev;
  135. platform_set_drvdata(pdev, card);
  136. snd_soc_card_set_drvdata(card, trimslice);
  137. ret = snd_soc_register_card(card);
  138. if (ret) {
  139. dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
  140. ret);
  141. goto err_fini_utils;
  142. }
  143. return 0;
  144. err_fini_utils:
  145. tegra_asoc_utils_fini(&trimslice->util_data);
  146. err:
  147. return ret;
  148. }
  149. static int __devexit tegra_snd_trimslice_remove(struct platform_device *pdev)
  150. {
  151. struct snd_soc_card *card = platform_get_drvdata(pdev);
  152. struct tegra_trimslice *trimslice = snd_soc_card_get_drvdata(card);
  153. snd_soc_unregister_card(card);
  154. tegra_asoc_utils_fini(&trimslice->util_data);
  155. return 0;
  156. }
  157. static struct platform_driver tegra_snd_trimslice_driver = {
  158. .driver = {
  159. .name = DRV_NAME,
  160. .owner = THIS_MODULE,
  161. },
  162. .probe = tegra_snd_trimslice_probe,
  163. .remove = __devexit_p(tegra_snd_trimslice_remove),
  164. };
  165. module_platform_driver(tegra_snd_trimslice_driver);
  166. MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
  167. MODULE_DESCRIPTION("Trimslice machine ASoC driver");
  168. MODULE_LICENSE("GPL");
  169. MODULE_ALIAS("platform:" DRV_NAME);