davinci-evm.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
  26. SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF)
  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_dai *codec_dai = rtd->dai->codec_dai;
  32. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  33. int ret = 0;
  34. unsigned sysclk;
  35. /* ASP1 on DM355 EVM is clocked by an external oscillator */
  36. if (machine_is_davinci_dm355_evm())
  37. sysclk = 27000000;
  38. /* ASP0 in DM6446 EVM is clocked by U55, as configured by
  39. * board-dm644x-evm.c using GPIOs from U18. There are six
  40. * options; here we "know" we use a 48 KHz sample rate.
  41. */
  42. else if (machine_is_davinci_evm())
  43. sysclk = 12288000;
  44. else
  45. return -EINVAL;
  46. /* set codec DAI configuration */
  47. ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT);
  48. if (ret < 0)
  49. return ret;
  50. /* set cpu DAI configuration */
  51. ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
  52. if (ret < 0)
  53. return ret;
  54. /* set the codec system clock */
  55. ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
  56. if (ret < 0)
  57. return ret;
  58. return 0;
  59. }
  60. static struct snd_soc_ops evm_ops = {
  61. .hw_params = evm_hw_params,
  62. };
  63. /* davinci-evm machine dapm widgets */
  64. static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
  65. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  66. SND_SOC_DAPM_LINE("Line Out", NULL),
  67. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  68. SND_SOC_DAPM_LINE("Line In", NULL),
  69. };
  70. /* davinci-evm machine audio_mapnections to the codec pins */
  71. static const struct snd_soc_dapm_route audio_map[] = {
  72. /* Headphone connected to HPLOUT, HPROUT */
  73. {"Headphone Jack", NULL, "HPLOUT"},
  74. {"Headphone Jack", NULL, "HPROUT"},
  75. /* Line Out connected to LLOUT, RLOUT */
  76. {"Line Out", NULL, "LLOUT"},
  77. {"Line Out", NULL, "RLOUT"},
  78. /* Mic connected to (MIC3L | MIC3R) */
  79. {"MIC3L", NULL, "Mic Bias 2V"},
  80. {"MIC3R", NULL, "Mic Bias 2V"},
  81. {"Mic Bias 2V", NULL, "Mic Jack"},
  82. /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
  83. {"LINE1L", NULL, "Line In"},
  84. {"LINE2L", NULL, "Line In"},
  85. {"LINE1R", NULL, "Line In"},
  86. {"LINE2R", NULL, "Line In"},
  87. };
  88. /* Logic for a aic3x as connected on a davinci-evm */
  89. static int evm_aic3x_init(struct snd_soc_codec *codec)
  90. {
  91. /* Add davinci-evm specific widgets */
  92. snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets,
  93. ARRAY_SIZE(aic3x_dapm_widgets));
  94. /* Set up davinci-evm specific audio path audio_map */
  95. snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
  96. /* not connected */
  97. snd_soc_dapm_disable_pin(codec, "MONO_LOUT");
  98. snd_soc_dapm_disable_pin(codec, "HPLCOM");
  99. snd_soc_dapm_disable_pin(codec, "HPRCOM");
  100. /* always connected */
  101. snd_soc_dapm_enable_pin(codec, "Headphone Jack");
  102. snd_soc_dapm_enable_pin(codec, "Line Out");
  103. snd_soc_dapm_enable_pin(codec, "Mic Jack");
  104. snd_soc_dapm_enable_pin(codec, "Line In");
  105. snd_soc_dapm_sync(codec);
  106. return 0;
  107. }
  108. /* davinci-evm digital audio interface glue - connects codec <--> CPU */
  109. static struct snd_soc_dai_link evm_dai = {
  110. .name = "TLV320AIC3X",
  111. .stream_name = "AIC3X",
  112. .cpu_dai = &davinci_i2s_dai,
  113. .codec_dai = &aic3x_dai,
  114. .init = evm_aic3x_init,
  115. .ops = &evm_ops,
  116. };
  117. /* davinci-evm audio machine driver */
  118. static struct snd_soc_card snd_soc_card_evm = {
  119. .name = "DaVinci EVM",
  120. .platform = &davinci_soc_platform,
  121. .dai_link = &evm_dai,
  122. .num_links = 1,
  123. };
  124. /* evm audio private data */
  125. static struct aic3x_setup_data evm_aic3x_setup = {
  126. .i2c_bus = 0,
  127. .i2c_address = 0x1b,
  128. };
  129. /* evm audio subsystem */
  130. static struct snd_soc_device evm_snd_devdata = {
  131. .card = &snd_soc_card_evm,
  132. .codec_dev = &soc_codec_dev_aic3x,
  133. .codec_data = &evm_aic3x_setup,
  134. };
  135. static struct resource evm_snd_resources[] = {
  136. {
  137. .start = DAVINCI_MCBSP_BASE,
  138. .end = DAVINCI_MCBSP_BASE + SZ_8K - 1,
  139. .flags = IORESOURCE_MEM,
  140. },
  141. };
  142. static struct evm_snd_platform_data evm_snd_data = {
  143. .tx_dma_ch = DM644X_DMACH_MCBSP_TX,
  144. .rx_dma_ch = DM644X_DMACH_MCBSP_RX,
  145. };
  146. static struct platform_device *evm_snd_device;
  147. static int __init evm_init(void)
  148. {
  149. int ret;
  150. evm_snd_device = platform_device_alloc("soc-audio", 0);
  151. if (!evm_snd_device)
  152. return -ENOMEM;
  153. platform_set_drvdata(evm_snd_device, &evm_snd_devdata);
  154. evm_snd_devdata.dev = &evm_snd_device->dev;
  155. platform_device_add_data(evm_snd_device, &evm_snd_data,
  156. sizeof(evm_snd_data));
  157. ret = platform_device_add_resources(evm_snd_device, evm_snd_resources,
  158. ARRAY_SIZE(evm_snd_resources));
  159. if (ret) {
  160. platform_device_put(evm_snd_device);
  161. return ret;
  162. }
  163. ret = platform_device_add(evm_snd_device);
  164. if (ret)
  165. platform_device_put(evm_snd_device);
  166. return ret;
  167. }
  168. static void __exit evm_exit(void)
  169. {
  170. platform_device_unregister(evm_snd_device);
  171. }
  172. module_init(evm_init);
  173. module_exit(evm_exit);
  174. MODULE_AUTHOR("Vladimir Barinov");
  175. MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
  176. MODULE_LICENSE("GPL");