davinci-evm.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * ASoC driver for TI DAVINCI EVM platform
  3. *
  4. * Author: Vladimir Barinov, <vbarinov@embeddedalley.com>
  5. * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/moduleparam.h>
  13. #include <linux/timer.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/platform_device.h>
  16. #include <sound/core.h>
  17. #include <sound/pcm.h>
  18. #include <sound/soc.h>
  19. #include <sound/soc-dapm.h>
  20. #include <asm/dma.h>
  21. #include <mach/hardware.h>
  22. #include "../codecs/tlv320aic3x.h"
  23. #include "davinci-pcm.h"
  24. #include "davinci-i2s.h"
  25. #define EVM_CODEC_CLOCK 22579200
  26. #define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
  27. SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF)
  28. static int evm_hw_params(struct snd_pcm_substream *substream,
  29. struct snd_pcm_hw_params *params)
  30. {
  31. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  32. struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
  33. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  34. int ret = 0;
  35. /* set codec DAI configuration */
  36. ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT);
  37. if (ret < 0)
  38. return ret;
  39. /* set cpu DAI configuration */
  40. ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
  41. if (ret < 0)
  42. return ret;
  43. /* set the codec system clock */
  44. ret = snd_soc_dai_set_sysclk(codec_dai, 0, EVM_CODEC_CLOCK,
  45. SND_SOC_CLOCK_OUT);
  46. if (ret < 0)
  47. return ret;
  48. return 0;
  49. }
  50. static struct snd_soc_ops evm_ops = {
  51. .hw_params = evm_hw_params,
  52. };
  53. /* davinci-evm machine dapm widgets */
  54. static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
  55. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  56. SND_SOC_DAPM_LINE("Line Out", NULL),
  57. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  58. SND_SOC_DAPM_LINE("Line In", NULL),
  59. };
  60. /* davinci-evm machine audio_mapnections to the codec pins */
  61. static const struct snd_soc_dapm_route audio_map[] = {
  62. /* Headphone connected to HPLOUT, HPROUT */
  63. {"Headphone Jack", NULL, "HPLOUT"},
  64. {"Headphone Jack", NULL, "HPROUT"},
  65. /* Line Out connected to LLOUT, RLOUT */
  66. {"Line Out", NULL, "LLOUT"},
  67. {"Line Out", NULL, "RLOUT"},
  68. /* Mic connected to (MIC3L | MIC3R) */
  69. {"MIC3L", NULL, "Mic Bias 2V"},
  70. {"MIC3R", NULL, "Mic Bias 2V"},
  71. {"Mic Bias 2V", NULL, "Mic Jack"},
  72. /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
  73. {"LINE1L", NULL, "Line In"},
  74. {"LINE2L", NULL, "Line In"},
  75. {"LINE1R", NULL, "Line In"},
  76. {"LINE2R", NULL, "Line In"},
  77. };
  78. /* Logic for a aic3x as connected on a davinci-evm */
  79. static int evm_aic3x_init(struct snd_soc_codec *codec)
  80. {
  81. /* Add davinci-evm specific widgets */
  82. snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets,
  83. ARRAY_SIZE(aic3x_dapm_widgets));
  84. /* Set up davinci-evm specific audio path audio_map */
  85. snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
  86. /* not connected */
  87. snd_soc_dapm_disable_pin(codec, "MONO_LOUT");
  88. snd_soc_dapm_disable_pin(codec, "HPLCOM");
  89. snd_soc_dapm_disable_pin(codec, "HPRCOM");
  90. /* always connected */
  91. snd_soc_dapm_enable_pin(codec, "Headphone Jack");
  92. snd_soc_dapm_enable_pin(codec, "Line Out");
  93. snd_soc_dapm_enable_pin(codec, "Mic Jack");
  94. snd_soc_dapm_enable_pin(codec, "Line In");
  95. snd_soc_dapm_sync(codec);
  96. return 0;
  97. }
  98. /* davinci-evm digital audio interface glue - connects codec <--> CPU */
  99. static struct snd_soc_dai_link evm_dai = {
  100. .name = "TLV320AIC3X",
  101. .stream_name = "AIC3X",
  102. .cpu_dai = &davinci_i2s_dai,
  103. .codec_dai = &aic3x_dai,
  104. .init = evm_aic3x_init,
  105. .ops = &evm_ops,
  106. };
  107. /* davinci-evm audio machine driver */
  108. static struct snd_soc_card snd_soc_card_evm = {
  109. .name = "DaVinci EVM",
  110. .platform = &davinci_soc_platform,
  111. .dai_link = &evm_dai,
  112. .num_links = 1,
  113. };
  114. /* evm audio private data */
  115. static struct aic3x_setup_data evm_aic3x_setup = {
  116. .i2c_bus = 0,
  117. .i2c_address = 0x1b,
  118. };
  119. /* evm audio subsystem */
  120. static struct snd_soc_device evm_snd_devdata = {
  121. .card = &snd_soc_card_evm,
  122. .codec_dev = &soc_codec_dev_aic3x,
  123. .codec_data = &evm_aic3x_setup,
  124. };
  125. static struct resource evm_snd_resources[] = {
  126. {
  127. .start = DAVINCI_MCBSP_BASE,
  128. .end = DAVINCI_MCBSP_BASE + SZ_8K - 1,
  129. .flags = IORESOURCE_MEM,
  130. },
  131. };
  132. static struct evm_snd_platform_data evm_snd_data = {
  133. .tx_dma_ch = DM644X_DMACH_MCBSP_TX,
  134. .rx_dma_ch = DM644X_DMACH_MCBSP_RX,
  135. };
  136. static struct platform_device *evm_snd_device;
  137. static int __init evm_init(void)
  138. {
  139. int ret;
  140. evm_snd_device = platform_device_alloc("soc-audio", 0);
  141. if (!evm_snd_device)
  142. return -ENOMEM;
  143. platform_set_drvdata(evm_snd_device, &evm_snd_devdata);
  144. evm_snd_devdata.dev = &evm_snd_device->dev;
  145. evm_snd_device->dev.platform_data = &evm_snd_data;
  146. ret = platform_device_add_resources(evm_snd_device, evm_snd_resources,
  147. ARRAY_SIZE(evm_snd_resources));
  148. if (ret) {
  149. platform_device_put(evm_snd_device);
  150. return ret;
  151. }
  152. ret = platform_device_add(evm_snd_device);
  153. if (ret)
  154. platform_device_put(evm_snd_device);
  155. return ret;
  156. }
  157. static void __exit evm_exit(void)
  158. {
  159. platform_device_unregister(evm_snd_device);
  160. }
  161. module_init(evm_init);
  162. module_exit(evm_exit);
  163. MODULE_AUTHOR("Vladimir Barinov");
  164. MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
  165. MODULE_LICENSE("GPL");