trimslice.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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 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. dev_err(&pdev->dev, "Can't allocate tegra_trimslice\n");
  108. return -ENOMEM;
  109. }
  110. card->dev = &pdev->dev;
  111. platform_set_drvdata(pdev, card);
  112. snd_soc_card_set_drvdata(card, trimslice);
  113. trimslice_tlv320aic23_dai.codec_of_node = of_parse_phandle(np,
  114. "nvidia,audio-codec", 0);
  115. if (!trimslice_tlv320aic23_dai.codec_of_node) {
  116. dev_err(&pdev->dev,
  117. "Property 'nvidia,audio-codec' missing or invalid\n");
  118. ret = -EINVAL;
  119. goto err;
  120. }
  121. trimslice_tlv320aic23_dai.cpu_of_node = of_parse_phandle(np,
  122. "nvidia,i2s-controller", 0);
  123. if (!trimslice_tlv320aic23_dai.cpu_of_node) {
  124. dev_err(&pdev->dev,
  125. "Property 'nvidia,i2s-controller' missing or invalid\n");
  126. ret = -EINVAL;
  127. goto err;
  128. }
  129. trimslice_tlv320aic23_dai.platform_of_node =
  130. trimslice_tlv320aic23_dai.cpu_of_node;
  131. ret = tegra_asoc_utils_init(&trimslice->util_data, &pdev->dev);
  132. if (ret)
  133. goto err;
  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 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 const struct of_device_id trimslice_of_match[] = {
  155. { .compatible = "nvidia,tegra-audio-trimslice", },
  156. {},
  157. };
  158. MODULE_DEVICE_TABLE(of, trimslice_of_match);
  159. static struct platform_driver tegra_snd_trimslice_driver = {
  160. .driver = {
  161. .name = DRV_NAME,
  162. .of_match_table = trimslice_of_match,
  163. },
  164. .probe = tegra_snd_trimslice_probe,
  165. .remove = tegra_snd_trimslice_remove,
  166. };
  167. module_platform_driver(tegra_snd_trimslice_driver);
  168. MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
  169. MODULE_DESCRIPTION("Trimslice machine ASoC driver");
  170. MODULE_LICENSE("GPL");
  171. MODULE_ALIAS("platform:" DRV_NAME);