trimslice.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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_asoc_utils.h"
  37. #define DRV_NAME "tegra-snd-trimslice"
  38. struct tegra_trimslice {
  39. struct tegra_asoc_utils_data util_data;
  40. };
  41. static int trimslice_asoc_hw_params(struct snd_pcm_substream *substream,
  42. struct snd_pcm_hw_params *params)
  43. {
  44. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  45. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  46. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  47. struct snd_soc_codec *codec = rtd->codec;
  48. struct snd_soc_card *card = codec->card;
  49. struct tegra_trimslice *trimslice = snd_soc_card_get_drvdata(card);
  50. int srate, mclk;
  51. int err;
  52. srate = params_rate(params);
  53. mclk = 128 * srate;
  54. err = tegra_asoc_utils_set_rate(&trimslice->util_data, srate, mclk);
  55. if (err < 0) {
  56. dev_err(card->dev, "Can't configure clocks\n");
  57. return err;
  58. }
  59. err = snd_soc_dai_set_fmt(codec_dai,
  60. SND_SOC_DAIFMT_I2S |
  61. SND_SOC_DAIFMT_NB_NF |
  62. SND_SOC_DAIFMT_CBS_CFS);
  63. if (err < 0) {
  64. dev_err(card->dev, "codec_dai fmt not set\n");
  65. return err;
  66. }
  67. err = snd_soc_dai_set_fmt(cpu_dai,
  68. SND_SOC_DAIFMT_I2S |
  69. SND_SOC_DAIFMT_NB_NF |
  70. SND_SOC_DAIFMT_CBS_CFS);
  71. if (err < 0) {
  72. dev_err(card->dev, "cpu_dai fmt not set\n");
  73. return err;
  74. }
  75. err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
  76. SND_SOC_CLOCK_IN);
  77. if (err < 0) {
  78. dev_err(card->dev, "codec_dai clock not set\n");
  79. return err;
  80. }
  81. return 0;
  82. }
  83. static struct snd_soc_ops trimslice_asoc_ops = {
  84. .hw_params = trimslice_asoc_hw_params,
  85. };
  86. static const struct snd_soc_dapm_widget trimslice_dapm_widgets[] = {
  87. SND_SOC_DAPM_HP("Line Out", NULL),
  88. SND_SOC_DAPM_LINE("Line In", NULL),
  89. };
  90. static const struct snd_soc_dapm_route trimslice_audio_map[] = {
  91. {"Line Out", NULL, "LOUT"},
  92. {"Line Out", NULL, "ROUT"},
  93. {"LLINEIN", NULL, "Line In"},
  94. {"RLINEIN", NULL, "Line In"},
  95. };
  96. static struct snd_soc_dai_link trimslice_tlv320aic23_dai = {
  97. .name = "TLV320AIC23",
  98. .stream_name = "AIC23",
  99. .codec_name = "tlv320aic23-codec.2-001a",
  100. .platform_name = "tegra20-i2s.0",
  101. .cpu_dai_name = "tegra20-i2s.0",
  102. .codec_dai_name = "tlv320aic23-hifi",
  103. .ops = &trimslice_asoc_ops,
  104. };
  105. static struct snd_soc_card snd_soc_trimslice = {
  106. .name = "tegra-trimslice",
  107. .owner = THIS_MODULE,
  108. .dai_link = &trimslice_tlv320aic23_dai,
  109. .num_links = 1,
  110. .dapm_widgets = trimslice_dapm_widgets,
  111. .num_dapm_widgets = ARRAY_SIZE(trimslice_dapm_widgets),
  112. .dapm_routes = trimslice_audio_map,
  113. .num_dapm_routes = ARRAY_SIZE(trimslice_audio_map),
  114. .fully_routed = true,
  115. };
  116. static __devinit int tegra_snd_trimslice_probe(struct platform_device *pdev)
  117. {
  118. struct snd_soc_card *card = &snd_soc_trimslice;
  119. struct tegra_trimslice *trimslice;
  120. int ret;
  121. trimslice = devm_kzalloc(&pdev->dev, sizeof(struct tegra_trimslice),
  122. GFP_KERNEL);
  123. if (!trimslice) {
  124. dev_err(&pdev->dev, "Can't allocate tegra_trimslice\n");
  125. ret = -ENOMEM;
  126. goto err;
  127. }
  128. ret = tegra_asoc_utils_init(&trimslice->util_data, &pdev->dev);
  129. if (ret)
  130. goto err;
  131. card->dev = &pdev->dev;
  132. platform_set_drvdata(pdev, card);
  133. snd_soc_card_set_drvdata(card, trimslice);
  134. ret = snd_soc_register_card(card);
  135. if (ret) {
  136. dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
  137. ret);
  138. goto err_fini_utils;
  139. }
  140. return 0;
  141. err_fini_utils:
  142. tegra_asoc_utils_fini(&trimslice->util_data);
  143. err:
  144. return ret;
  145. }
  146. static int __devexit tegra_snd_trimslice_remove(struct platform_device *pdev)
  147. {
  148. struct snd_soc_card *card = platform_get_drvdata(pdev);
  149. struct tegra_trimslice *trimslice = snd_soc_card_get_drvdata(card);
  150. snd_soc_unregister_card(card);
  151. tegra_asoc_utils_fini(&trimslice->util_data);
  152. return 0;
  153. }
  154. static struct platform_driver tegra_snd_trimslice_driver = {
  155. .driver = {
  156. .name = DRV_NAME,
  157. .owner = THIS_MODULE,
  158. },
  159. .probe = tegra_snd_trimslice_probe,
  160. .remove = __devexit_p(tegra_snd_trimslice_remove),
  161. };
  162. module_platform_driver(tegra_snd_trimslice_driver);
  163. MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
  164. MODULE_DESCRIPTION("Trimslice machine ASoC driver");
  165. MODULE_LICENSE("GPL");
  166. MODULE_ALIAS("platform:" DRV_NAME);