trimslice.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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_dapm_context *dapm = &codec->dapm;
  103. snd_soc_dapm_nc_pin(dapm, "LHPOUT");
  104. snd_soc_dapm_nc_pin(dapm, "RHPOUT");
  105. snd_soc_dapm_nc_pin(dapm, "MICIN");
  106. snd_soc_dapm_sync(dapm);
  107. return 0;
  108. }
  109. static struct snd_soc_dai_link trimslice_tlv320aic23_dai = {
  110. .name = "TLV320AIC23",
  111. .stream_name = "AIC23",
  112. .codec_name = "tlv320aic23-codec.2-001a",
  113. .platform_name = "tegra-pcm-audio",
  114. .cpu_dai_name = "tegra-i2s.0",
  115. .codec_dai_name = "tlv320aic23-hifi",
  116. .init = trimslice_asoc_init,
  117. .ops = &trimslice_asoc_ops,
  118. };
  119. static struct snd_soc_card snd_soc_trimslice = {
  120. .name = "tegra-trimslice",
  121. .dai_link = &trimslice_tlv320aic23_dai,
  122. .num_links = 1,
  123. .dapm_widgets = trimslice_dapm_widgets,
  124. .num_dapm_widgets = ARRAY_SIZE(trimslice_dapm_widgets),
  125. .dapm_routes = trimslice_audio_map,
  126. .num_dapm_routes = ARRAY_SIZE(trimslice_audio_map),
  127. };
  128. static __devinit int tegra_snd_trimslice_probe(struct platform_device *pdev)
  129. {
  130. struct snd_soc_card *card = &snd_soc_trimslice;
  131. struct tegra_trimslice *trimslice;
  132. int ret;
  133. trimslice = kzalloc(sizeof(struct tegra_trimslice), GFP_KERNEL);
  134. if (!trimslice) {
  135. dev_err(&pdev->dev, "Can't allocate tegra_trimslice\n");
  136. return -ENOMEM;
  137. }
  138. ret = tegra_asoc_utils_init(&trimslice->util_data, &pdev->dev);
  139. if (ret)
  140. goto err_free_trimslice;
  141. card->dev = &pdev->dev;
  142. platform_set_drvdata(pdev, card);
  143. snd_soc_card_set_drvdata(card, trimslice);
  144. ret = snd_soc_register_card(card);
  145. if (ret) {
  146. dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
  147. ret);
  148. goto err_fini_utils;
  149. }
  150. return 0;
  151. err_fini_utils:
  152. tegra_asoc_utils_fini(&trimslice->util_data);
  153. err_free_trimslice:
  154. kfree(trimslice);
  155. return ret;
  156. }
  157. static int __devexit tegra_snd_trimslice_remove(struct platform_device *pdev)
  158. {
  159. struct snd_soc_card *card = platform_get_drvdata(pdev);
  160. struct tegra_trimslice *trimslice = snd_soc_card_get_drvdata(card);
  161. snd_soc_unregister_card(card);
  162. tegra_asoc_utils_fini(&trimslice->util_data);
  163. kfree(trimslice);
  164. return 0;
  165. }
  166. static struct platform_driver tegra_snd_trimslice_driver = {
  167. .driver = {
  168. .name = DRV_NAME,
  169. .owner = THIS_MODULE,
  170. },
  171. .probe = tegra_snd_trimslice_probe,
  172. .remove = __devexit_p(tegra_snd_trimslice_remove),
  173. };
  174. static int __init snd_tegra_trimslice_init(void)
  175. {
  176. return platform_driver_register(&tegra_snd_trimslice_driver);
  177. }
  178. module_init(snd_tegra_trimslice_init);
  179. static void __exit snd_tegra_trimslice_exit(void)
  180. {
  181. platform_driver_unregister(&tegra_snd_trimslice_driver);
  182. }
  183. module_exit(snd_tegra_trimslice_exit);
  184. MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
  185. MODULE_DESCRIPTION("Trimslice machine ASoC driver");
  186. MODULE_LICENSE("GPL");
  187. MODULE_ALIAS("platform:" DRV_NAME);