trimslice.c 5.4 KB

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