trimslice.c 5.3 KB

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