eukrea-tlv320.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * eukrea-tlv320.c -- SoC audio for eukrea_cpuimxXX in I2S mode
  3. *
  4. * Copyright 2010 Eric Bénard, Eukréa Electromatique <eric@eukrea.com>
  5. *
  6. * based on sound/soc/s3c24xx/s3c24xx_simtec_tlv320aic23.c
  7. * which is Copyright 2009 Simtec Electronics
  8. * and on sound/soc/imx/phycore-ac97.c which is
  9. * Copyright 2009 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License as published by the
  13. * Free Software Foundation; either version 2 of the License, or (at your
  14. * option) any later version.
  15. *
  16. */
  17. #include <linux/module.h>
  18. #include <linux/moduleparam.h>
  19. #include <linux/device.h>
  20. #include <linux/i2c.h>
  21. #include <sound/core.h>
  22. #include <sound/pcm.h>
  23. #include <sound/soc.h>
  24. #include <asm/mach-types.h>
  25. #include "../codecs/tlv320aic23.h"
  26. #include "imx-ssi.h"
  27. #include "imx-audmux.h"
  28. #define CODEC_CLOCK 12000000
  29. static int eukrea_tlv320_hw_params(struct snd_pcm_substream *substream,
  30. struct snd_pcm_hw_params *params)
  31. {
  32. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  33. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  34. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  35. int ret;
  36. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
  37. SND_SOC_DAIFMT_NB_NF |
  38. SND_SOC_DAIFMT_CBM_CFM);
  39. if (ret) {
  40. dev_err(cpu_dai->dev,
  41. "Failed to set the cpu dai format.\n");
  42. return ret;
  43. }
  44. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
  45. SND_SOC_DAIFMT_NB_NF |
  46. SND_SOC_DAIFMT_CBM_CFM);
  47. if (ret) {
  48. dev_err(cpu_dai->dev,
  49. "Failed to set the codec format.\n");
  50. return ret;
  51. }
  52. ret = snd_soc_dai_set_sysclk(codec_dai, 0,
  53. CODEC_CLOCK, SND_SOC_CLOCK_OUT);
  54. if (ret) {
  55. dev_err(cpu_dai->dev,
  56. "Failed to set the codec sysclk.\n");
  57. return ret;
  58. }
  59. snd_soc_dai_set_tdm_slot(cpu_dai, 0xffffffc, 0xffffffc, 2, 0);
  60. ret = snd_soc_dai_set_sysclk(cpu_dai, IMX_SSP_SYS_CLK, 0,
  61. SND_SOC_CLOCK_IN);
  62. if (ret) {
  63. dev_err(cpu_dai->dev,
  64. "Can't set the IMX_SSP_SYS_CLK CPU system clock.\n");
  65. return ret;
  66. }
  67. return 0;
  68. }
  69. static struct snd_soc_ops eukrea_tlv320_snd_ops = {
  70. .hw_params = eukrea_tlv320_hw_params,
  71. };
  72. static struct snd_soc_dai_link eukrea_tlv320_dai = {
  73. .name = "tlv320aic23",
  74. .stream_name = "TLV320AIC23",
  75. .codec_dai_name = "tlv320aic23-hifi",
  76. .platform_name = "imx-ssi.0",
  77. .codec_name = "tlv320aic23-codec.0-001a",
  78. .cpu_dai_name = "imx-ssi.0",
  79. .ops = &eukrea_tlv320_snd_ops,
  80. };
  81. static struct snd_soc_card eukrea_tlv320 = {
  82. .name = "cpuimx-audio",
  83. .owner = THIS_MODULE,
  84. .dai_link = &eukrea_tlv320_dai,
  85. .num_links = 1,
  86. };
  87. static int eukrea_tlv320_probe(struct platform_device *pdev)
  88. {
  89. int ret;
  90. int int_port = 0, ext_port;
  91. if (machine_is_eukrea_cpuimx27()) {
  92. imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0,
  93. IMX_AUDMUX_V1_PCR_SYN |
  94. IMX_AUDMUX_V1_PCR_TFSDIR |
  95. IMX_AUDMUX_V1_PCR_TCLKDIR |
  96. IMX_AUDMUX_V1_PCR_RFSDIR |
  97. IMX_AUDMUX_V1_PCR_RCLKDIR |
  98. IMX_AUDMUX_V1_PCR_TFCSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4) |
  99. IMX_AUDMUX_V1_PCR_RFCSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4) |
  100. IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4)
  101. );
  102. imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR3_SSI_PINS_4,
  103. IMX_AUDMUX_V1_PCR_SYN |
  104. IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_HPCR1_SSI0)
  105. );
  106. } else if (machine_is_eukrea_cpuimx25sd() ||
  107. machine_is_eukrea_cpuimx35sd() ||
  108. machine_is_eukrea_cpuimx51sd()) {
  109. ext_port = machine_is_eukrea_cpuimx25sd() ? 4 : 3;
  110. imx_audmux_v2_configure_port(int_port,
  111. IMX_AUDMUX_V2_PTCR_SYN |
  112. IMX_AUDMUX_V2_PTCR_TFSDIR |
  113. IMX_AUDMUX_V2_PTCR_TFSEL(ext_port) |
  114. IMX_AUDMUX_V2_PTCR_TCLKDIR |
  115. IMX_AUDMUX_V2_PTCR_TCSEL(ext_port),
  116. IMX_AUDMUX_V2_PDCR_RXDSEL(ext_port)
  117. );
  118. imx_audmux_v2_configure_port(ext_port,
  119. IMX_AUDMUX_V2_PTCR_SYN,
  120. IMX_AUDMUX_V2_PDCR_RXDSEL(int_port)
  121. );
  122. } else {
  123. /* return happy. We might run on a totally different machine */
  124. return 0;
  125. }
  126. eukrea_tlv320.dev = &pdev->dev;
  127. ret = snd_soc_register_card(&eukrea_tlv320);
  128. if (ret)
  129. dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
  130. return ret;
  131. }
  132. static int eukrea_tlv320_remove(struct platform_device *pdev)
  133. {
  134. snd_soc_unregister_card(&eukrea_tlv320);
  135. return 0;
  136. }
  137. static struct platform_driver eukrea_tlv320_driver = {
  138. .driver = {
  139. .name = "eukrea_tlv320",
  140. .owner = THIS_MODULE,
  141. },
  142. .probe = eukrea_tlv320_probe,
  143. .remove = eukrea_tlv320_remove,
  144. };
  145. module_platform_driver(eukrea_tlv320_driver);
  146. MODULE_AUTHOR("Eric Bénard <eric@eukrea.com>");
  147. MODULE_DESCRIPTION("CPUIMX ALSA SoC driver");
  148. MODULE_LICENSE("GPL");
  149. MODULE_ALIAS("platform:eukrea_tlv320");