davinci-evm.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * ASoC driver for TI DAVINCI EVM platform
  3. *
  4. * Author: Vladimir Barinov, <vbarinov@ru.mvista.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/mach-types.h>
  21. #include <asm/dma.h>
  22. #include <asm/arch/hardware.h>
  23. #include "../codecs/tlv320aic3x.h"
  24. #include "davinci-pcm.h"
  25. #include "davinci-i2s.h"
  26. #define EVM_CODEC_CLOCK 22579200
  27. static int evm_hw_params(struct snd_pcm_substream *substream,
  28. struct snd_pcm_hw_params *params)
  29. {
  30. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  31. struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
  32. struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
  33. int ret = 0;
  34. /* set codec DAI configuration */
  35. ret = codec_dai->dai_ops.set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
  36. SND_SOC_DAIFMT_CBM_CFM);
  37. if (ret < 0)
  38. return ret;
  39. /* set cpu DAI configuration */
  40. ret = cpu_dai->dai_ops.set_fmt(cpu_dai, SND_SOC_DAIFMT_CBM_CFM |
  41. SND_SOC_DAIFMT_IB_NF);
  42. if (ret < 0)
  43. return ret;
  44. /* set the codec system clock */
  45. ret = codec_dai->dai_ops.set_sysclk(codec_dai, 0, EVM_CODEC_CLOCK,
  46. SND_SOC_CLOCK_OUT);
  47. if (ret < 0)
  48. return ret;
  49. return 0;
  50. }
  51. static struct snd_soc_ops evm_ops = {
  52. .hw_params = evm_hw_params,
  53. };
  54. /* davinci-evm machine dapm widgets */
  55. static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
  56. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  57. SND_SOC_DAPM_LINE("Line Out", NULL),
  58. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  59. SND_SOC_DAPM_LINE("Line In", NULL),
  60. };
  61. /* davinci-evm machine audio_mapnections to the codec pins */
  62. static const char *audio_map[][3] = {
  63. /* Headphone connected to HPLOUT, HPROUT */
  64. {"Headphone Jack", NULL, "HPLOUT"},
  65. {"Headphone Jack", NULL, "HPROUT"},
  66. /* Line Out connected to LLOUT, RLOUT */
  67. {"Line Out", NULL, "LLOUT"},
  68. {"Line Out", NULL, "RLOUT"},
  69. /* Mic connected to (MIC3L | MIC3R) */
  70. {"MIC3L", NULL, "Mic Bias 2V"},
  71. {"MIC3R", NULL, "Mic Bias 2V"},
  72. {"Mic Bias 2V", NULL, "Mic Jack"},
  73. /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
  74. {"LINE1L", NULL, "Line In"},
  75. {"LINE2L", NULL, "Line In"},
  76. {"LINE1R", NULL, "Line In"},
  77. {"LINE2R", NULL, "Line In"},
  78. {NULL, NULL, NULL},
  79. };
  80. /* Logic for a aic3x as connected on a davinci-evm */
  81. static int evm_aic3x_init(struct snd_soc_codec *codec)
  82. {
  83. int i;
  84. /* Add davinci-evm specific widgets */
  85. for (i = 0; i < ARRAY_SIZE(aic3x_dapm_widgets); i++)
  86. snd_soc_dapm_new_control(codec, &aic3x_dapm_widgets[i]);
  87. /* Set up davinci-evm specific audio path audio_map */
  88. for (i = 0; audio_map[i][0] != NULL; i++)
  89. snd_soc_dapm_connect_input(codec, audio_map[i][0],
  90. audio_map[i][1], audio_map[i][2]);
  91. /* not connected */
  92. snd_soc_dapm_set_endpoint(codec, "MONO_LOUT", 0);
  93. snd_soc_dapm_set_endpoint(codec, "HPLCOM", 0);
  94. snd_soc_dapm_set_endpoint(codec, "HPRCOM", 0);
  95. /* always connected */
  96. snd_soc_dapm_set_endpoint(codec, "Headphone Jack", 1);
  97. snd_soc_dapm_set_endpoint(codec, "Line Out", 1);
  98. snd_soc_dapm_set_endpoint(codec, "Mic Jack", 1);
  99. snd_soc_dapm_set_endpoint(codec, "Line In", 1);
  100. snd_soc_dapm_sync_endpoints(codec);
  101. return 0;
  102. }
  103. /* davinci-evm digital audio interface glue - connects codec <--> CPU */
  104. static struct snd_soc_dai_link evm_dai = {
  105. .name = "TLV320AIC3X",
  106. .stream_name = "AIC3X",
  107. .cpu_dai = &davinci_i2s_dai,
  108. .codec_dai = &aic3x_dai,
  109. .init = evm_aic3x_init,
  110. .ops = &evm_ops,
  111. };
  112. /* davinci-evm audio machine driver */
  113. static struct snd_soc_machine snd_soc_machine_evm = {
  114. .name = "DaVinci EVM",
  115. .dai_link = &evm_dai,
  116. .num_links = 1,
  117. };
  118. /* evm audio private data */
  119. static struct aic3x_setup_data evm_aic3x_setup = {
  120. .i2c_address = 0x1b,
  121. };
  122. /* evm audio subsystem */
  123. static struct snd_soc_device evm_snd_devdata = {
  124. .machine = &snd_soc_machine_evm,
  125. .platform = &davinci_soc_platform,
  126. .codec_dev = &soc_codec_dev_aic3x,
  127. .codec_data = &evm_aic3x_setup,
  128. };
  129. static struct resource evm_snd_resources[] = {
  130. {
  131. .start = DAVINCI_MCBSP_BASE,
  132. .end = DAVINCI_MCBSP_BASE + SZ_8K - 1,
  133. .flags = IORESOURCE_MEM,
  134. },
  135. };
  136. static struct evm_snd_platform_data evm_snd_data = {
  137. .tx_dma_ch = DM644X_DMACH_MCBSP_TX,
  138. .rx_dma_ch = DM644X_DMACH_MCBSP_RX,
  139. };
  140. static struct platform_device *evm_snd_device;
  141. static int __init evm_init(void)
  142. {
  143. int ret;
  144. evm_snd_device = platform_device_alloc("soc-audio", 0);
  145. if (!evm_snd_device)
  146. return -ENOMEM;
  147. platform_set_drvdata(evm_snd_device, &evm_snd_devdata);
  148. evm_snd_devdata.dev = &evm_snd_device->dev;
  149. evm_snd_device->dev.platform_data = &evm_snd_data;
  150. ret = platform_device_add_resources(evm_snd_device, evm_snd_resources,
  151. ARRAY_SIZE(evm_snd_resources));
  152. if (ret) {
  153. platform_device_put(evm_snd_device);
  154. return ret;
  155. }
  156. ret = platform_device_add(evm_snd_device);
  157. if (ret)
  158. platform_device_put(evm_snd_device);
  159. return ret;
  160. }
  161. static void __exit evm_exit(void)
  162. {
  163. platform_device_unregister(evm_snd_device);
  164. }
  165. module_init(evm_init);
  166. module_exit(evm_exit);
  167. MODULE_AUTHOR("Vladimir Barinov");
  168. MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
  169. MODULE_LICENSE("GPL");