davinci-evm.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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 <asm/mach-types.h>
  22. #include <mach/asp.h>
  23. #include <mach/edma.h>
  24. #include <mach/mux.h>
  25. #include "../codecs/tlv320aic3x.h"
  26. #include "../codecs/spdif_transciever.h"
  27. #include "davinci-pcm.h"
  28. #include "davinci-i2s.h"
  29. #include "davinci-mcasp.h"
  30. #define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
  31. SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF)
  32. static int evm_hw_params(struct snd_pcm_substream *substream,
  33. struct snd_pcm_hw_params *params)
  34. {
  35. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  36. struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
  37. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  38. int ret = 0;
  39. unsigned sysclk;
  40. /* ASP1 on DM355 EVM is clocked by an external oscillator */
  41. if (machine_is_davinci_dm355_evm() || machine_is_davinci_dm6467_evm())
  42. sysclk = 27000000;
  43. /* ASP0 in DM6446 EVM is clocked by U55, as configured by
  44. * board-dm644x-evm.c using GPIOs from U18. There are six
  45. * options; here we "know" we use a 48 KHz sample rate.
  46. */
  47. else if (machine_is_davinci_evm())
  48. sysclk = 12288000;
  49. else if (machine_is_davinci_da830_evm())
  50. sysclk = 24576000;
  51. else
  52. return -EINVAL;
  53. /* set codec DAI configuration */
  54. ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT);
  55. if (ret < 0)
  56. return ret;
  57. /* set cpu DAI configuration */
  58. ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
  59. if (ret < 0)
  60. return ret;
  61. /* set the codec system clock */
  62. ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
  63. if (ret < 0)
  64. return ret;
  65. return 0;
  66. }
  67. static struct snd_soc_ops evm_ops = {
  68. .hw_params = evm_hw_params,
  69. };
  70. /* davinci-evm machine dapm widgets */
  71. static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
  72. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  73. SND_SOC_DAPM_LINE("Line Out", NULL),
  74. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  75. SND_SOC_DAPM_LINE("Line In", NULL),
  76. };
  77. /* davinci-evm machine audio_mapnections to the codec pins */
  78. static const struct snd_soc_dapm_route audio_map[] = {
  79. /* Headphone connected to HPLOUT, HPROUT */
  80. {"Headphone Jack", NULL, "HPLOUT"},
  81. {"Headphone Jack", NULL, "HPROUT"},
  82. /* Line Out connected to LLOUT, RLOUT */
  83. {"Line Out", NULL, "LLOUT"},
  84. {"Line Out", NULL, "RLOUT"},
  85. /* Mic connected to (MIC3L | MIC3R) */
  86. {"MIC3L", NULL, "Mic Bias 2V"},
  87. {"MIC3R", NULL, "Mic Bias 2V"},
  88. {"Mic Bias 2V", NULL, "Mic Jack"},
  89. /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
  90. {"LINE1L", NULL, "Line In"},
  91. {"LINE2L", NULL, "Line In"},
  92. {"LINE1R", NULL, "Line In"},
  93. {"LINE2R", NULL, "Line In"},
  94. };
  95. /* Logic for a aic3x as connected on a davinci-evm */
  96. static int evm_aic3x_init(struct snd_soc_codec *codec)
  97. {
  98. /* Add davinci-evm specific widgets */
  99. snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets,
  100. ARRAY_SIZE(aic3x_dapm_widgets));
  101. /* Set up davinci-evm specific audio path audio_map */
  102. snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
  103. /* not connected */
  104. snd_soc_dapm_disable_pin(codec, "MONO_LOUT");
  105. snd_soc_dapm_disable_pin(codec, "HPLCOM");
  106. snd_soc_dapm_disable_pin(codec, "HPRCOM");
  107. /* always connected */
  108. snd_soc_dapm_enable_pin(codec, "Headphone Jack");
  109. snd_soc_dapm_enable_pin(codec, "Line Out");
  110. snd_soc_dapm_enable_pin(codec, "Mic Jack");
  111. snd_soc_dapm_enable_pin(codec, "Line In");
  112. snd_soc_dapm_sync(codec);
  113. return 0;
  114. }
  115. /* davinci-evm digital audio interface glue - connects codec <--> CPU */
  116. static struct snd_soc_dai_link evm_dai = {
  117. .name = "TLV320AIC3X",
  118. .stream_name = "AIC3X",
  119. .cpu_dai = &davinci_i2s_dai,
  120. .codec_dai = &aic3x_dai,
  121. .init = evm_aic3x_init,
  122. .ops = &evm_ops,
  123. };
  124. static struct snd_soc_dai_link dm6467_evm_dai[] = {
  125. {
  126. .name = "TLV320AIC3X",
  127. .stream_name = "AIC3X",
  128. .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_I2S_DAI],
  129. .codec_dai = &aic3x_dai,
  130. .init = evm_aic3x_init,
  131. .ops = &evm_ops,
  132. },
  133. {
  134. .name = "McASP",
  135. .stream_name = "spdif",
  136. .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_DIT_DAI],
  137. .codec_dai = &dit_stub_dai,
  138. .ops = &evm_ops,
  139. },
  140. };
  141. static struct snd_soc_dai_link da830_evm_dai = {
  142. .name = "TLV320AIC3X",
  143. .stream_name = "AIC3X",
  144. .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_I2S_DAI],
  145. .codec_dai = &aic3x_dai,
  146. .init = evm_aic3x_init,
  147. .ops = &evm_ops,
  148. };
  149. /* davinci-evm audio machine driver */
  150. static struct snd_soc_card snd_soc_card_evm = {
  151. .name = "DaVinci EVM",
  152. .platform = &davinci_soc_platform,
  153. .dai_link = &evm_dai,
  154. .num_links = 1,
  155. };
  156. /* davinci dm6467 evm audio machine driver */
  157. static struct snd_soc_card dm6467_snd_soc_card_evm = {
  158. .name = "DaVinci DM6467 EVM",
  159. .platform = &davinci_soc_platform,
  160. .dai_link = dm6467_evm_dai,
  161. .num_links = ARRAY_SIZE(dm6467_evm_dai),
  162. };
  163. static struct snd_soc_card da830_snd_soc_card = {
  164. .name = "DA830 EVM",
  165. .dai_link = &da830_evm_dai,
  166. .platform = &davinci_soc_platform,
  167. .num_links = 1,
  168. };
  169. /* evm audio private data */
  170. static struct aic3x_setup_data evm_aic3x_setup = {
  171. .i2c_bus = 1,
  172. .i2c_address = 0x1b,
  173. };
  174. /* dm6467 evm audio private data */
  175. static struct aic3x_setup_data dm6467_evm_aic3x_setup = {
  176. .i2c_bus = 1,
  177. .i2c_address = 0x18,
  178. };
  179. static struct aic3x_setup_data da830_evm_aic3x_setup = {
  180. .i2c_bus = 1,
  181. .i2c_address = 0x18,
  182. };
  183. /* evm audio subsystem */
  184. static struct snd_soc_device evm_snd_devdata = {
  185. .card = &snd_soc_card_evm,
  186. .codec_dev = &soc_codec_dev_aic3x,
  187. .codec_data = &evm_aic3x_setup,
  188. };
  189. /* evm audio subsystem */
  190. static struct snd_soc_device dm6467_evm_snd_devdata = {
  191. .card = &dm6467_snd_soc_card_evm,
  192. .codec_dev = &soc_codec_dev_aic3x,
  193. .codec_data = &dm6467_evm_aic3x_setup,
  194. };
  195. /* evm audio subsystem */
  196. static struct snd_soc_device da830_evm_snd_devdata = {
  197. .card = &da830_snd_soc_card,
  198. .codec_dev = &soc_codec_dev_aic3x,
  199. .codec_data = &da830_evm_aic3x_setup,
  200. };
  201. static struct platform_device *evm_snd_device;
  202. static int __init evm_init(void)
  203. {
  204. struct snd_soc_device *evm_snd_dev_data;
  205. int index;
  206. int ret;
  207. if (machine_is_davinci_evm()) {
  208. evm_snd_dev_data = &evm_snd_devdata;
  209. index = 0;
  210. } else if (machine_is_davinci_dm355_evm()) {
  211. evm_snd_dev_data = &evm_snd_devdata;
  212. index = 1;
  213. } else if (machine_is_davinci_dm6467_evm()) {
  214. evm_snd_dev_data = &dm6467_evm_snd_devdata;
  215. index = 0;
  216. } else if (machine_is_davinci_da830_evm()) {
  217. evm_snd_dev_data = &da830_evm_snd_devdata;
  218. index = 1;
  219. } else
  220. return -EINVAL;
  221. evm_snd_device = platform_device_alloc("soc-audio", index);
  222. if (!evm_snd_device)
  223. return -ENOMEM;
  224. platform_set_drvdata(evm_snd_device, evm_snd_dev_data);
  225. evm_snd_dev_data->dev = &evm_snd_device->dev;
  226. ret = platform_device_add(evm_snd_device);
  227. if (ret)
  228. platform_device_put(evm_snd_device);
  229. return ret;
  230. }
  231. static void __exit evm_exit(void)
  232. {
  233. platform_device_unregister(evm_snd_device);
  234. }
  235. module_init(evm_init);
  236. module_exit(evm_exit);
  237. MODULE_AUTHOR("Vladimir Barinov");
  238. MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
  239. MODULE_LICENSE("GPL");