trimslice.c 6.1 KB

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