trimslice.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 <linux/module.h>
  27. #include <linux/of.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_codec *codec = codec_dai->codec;
  47. struct snd_soc_card *card = codec->card;
  48. struct tegra_trimslice *trimslice = snd_soc_card_get_drvdata(card);
  49. int srate, mclk;
  50. int err;
  51. srate = params_rate(params);
  52. mclk = 128 * srate;
  53. err = tegra_asoc_utils_set_rate(&trimslice->util_data, srate, mclk);
  54. if (err < 0) {
  55. dev_err(card->dev, "Can't configure clocks\n");
  56. return err;
  57. }
  58. err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
  59. SND_SOC_CLOCK_IN);
  60. if (err < 0) {
  61. dev_err(card->dev, "codec_dai clock not set\n");
  62. return err;
  63. }
  64. return 0;
  65. }
  66. static struct snd_soc_ops trimslice_asoc_ops = {
  67. .hw_params = trimslice_asoc_hw_params,
  68. };
  69. static const struct snd_soc_dapm_widget trimslice_dapm_widgets[] = {
  70. SND_SOC_DAPM_HP("Line Out", NULL),
  71. SND_SOC_DAPM_LINE("Line In", NULL),
  72. };
  73. static const struct snd_soc_dapm_route trimslice_audio_map[] = {
  74. {"Line Out", NULL, "LOUT"},
  75. {"Line Out", NULL, "ROUT"},
  76. {"LLINEIN", NULL, "Line In"},
  77. {"RLINEIN", NULL, "Line In"},
  78. };
  79. static struct snd_soc_dai_link trimslice_tlv320aic23_dai = {
  80. .name = "TLV320AIC23",
  81. .stream_name = "AIC23",
  82. .codec_dai_name = "tlv320aic23-hifi",
  83. .ops = &trimslice_asoc_ops,
  84. .dai_fmt = SND_SOC_DAIFMT_I2S |
  85. SND_SOC_DAIFMT_NB_NF |
  86. SND_SOC_DAIFMT_CBS_CFS,
  87. };
  88. static struct snd_soc_card snd_soc_trimslice = {
  89. .name = "tegra-trimslice",
  90. .owner = THIS_MODULE,
  91. .dai_link = &trimslice_tlv320aic23_dai,
  92. .num_links = 1,
  93. .dapm_widgets = trimslice_dapm_widgets,
  94. .num_dapm_widgets = ARRAY_SIZE(trimslice_dapm_widgets),
  95. .dapm_routes = trimslice_audio_map,
  96. .num_dapm_routes = ARRAY_SIZE(trimslice_audio_map),
  97. .fully_routed = true,
  98. };
  99. static int tegra_snd_trimslice_probe(struct platform_device *pdev)
  100. {
  101. struct device_node *np = pdev->dev.of_node;
  102. struct snd_soc_card *card = &snd_soc_trimslice;
  103. struct tegra_trimslice *trimslice;
  104. int ret;
  105. trimslice = devm_kzalloc(&pdev->dev, sizeof(struct tegra_trimslice),
  106. GFP_KERNEL);
  107. if (!trimslice) {
  108. dev_err(&pdev->dev, "Can't allocate tegra_trimslice\n");
  109. return -ENOMEM;
  110. }
  111. card->dev = &pdev->dev;
  112. platform_set_drvdata(pdev, card);
  113. snd_soc_card_set_drvdata(card, trimslice);
  114. trimslice_tlv320aic23_dai.codec_of_node = of_parse_phandle(np,
  115. "nvidia,audio-codec", 0);
  116. if (!trimslice_tlv320aic23_dai.codec_of_node) {
  117. dev_err(&pdev->dev,
  118. "Property 'nvidia,audio-codec' missing or invalid\n");
  119. ret = -EINVAL;
  120. goto err;
  121. }
  122. trimslice_tlv320aic23_dai.cpu_of_node = of_parse_phandle(np,
  123. "nvidia,i2s-controller", 0);
  124. if (!trimslice_tlv320aic23_dai.cpu_of_node) {
  125. dev_err(&pdev->dev,
  126. "Property 'nvidia,i2s-controller' missing or invalid\n");
  127. ret = -EINVAL;
  128. goto err;
  129. }
  130. trimslice_tlv320aic23_dai.platform_of_node =
  131. trimslice_tlv320aic23_dai.cpu_of_node;
  132. ret = tegra_asoc_utils_init(&trimslice->util_data, &pdev->dev);
  133. if (ret)
  134. goto err;
  135. ret = snd_soc_register_card(card);
  136. if (ret) {
  137. dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
  138. ret);
  139. goto err_fini_utils;
  140. }
  141. return 0;
  142. err_fini_utils:
  143. tegra_asoc_utils_fini(&trimslice->util_data);
  144. err:
  145. return ret;
  146. }
  147. static int tegra_snd_trimslice_remove(struct platform_device *pdev)
  148. {
  149. struct snd_soc_card *card = platform_get_drvdata(pdev);
  150. struct tegra_trimslice *trimslice = snd_soc_card_get_drvdata(card);
  151. snd_soc_unregister_card(card);
  152. tegra_asoc_utils_fini(&trimslice->util_data);
  153. return 0;
  154. }
  155. static const struct of_device_id trimslice_of_match[] = {
  156. { .compatible = "nvidia,tegra-audio-trimslice", },
  157. {},
  158. };
  159. MODULE_DEVICE_TABLE(of, trimslice_of_match);
  160. static struct platform_driver tegra_snd_trimslice_driver = {
  161. .driver = {
  162. .name = DRV_NAME,
  163. .owner = THIS_MODULE,
  164. .of_match_table = trimslice_of_match,
  165. },
  166. .probe = tegra_snd_trimslice_probe,
  167. .remove = tegra_snd_trimslice_remove,
  168. };
  169. module_platform_driver(tegra_snd_trimslice_driver);
  170. MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
  171. MODULE_DESCRIPTION("Trimslice machine ASoC driver");
  172. MODULE_LICENSE("GPL");
  173. MODULE_ALIAS("platform:" DRV_NAME);