davinci-evm.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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 <linux/i2c.h>
  17. #include <sound/core.h>
  18. #include <sound/pcm.h>
  19. #include <sound/soc.h>
  20. #include <sound/soc-dapm.h>
  21. #include <asm/dma.h>
  22. #include <asm/mach-types.h>
  23. #include <mach/asp.h>
  24. #include <mach/edma.h>
  25. #include <mach/mux.h>
  26. #include "../codecs/tlv320aic3x.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->codec_dai;
  37. struct snd_soc_dai *cpu_dai = rtd->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. machine_is_davinci_dm365_evm())
  43. sysclk = 27000000;
  44. /* ASP0 in DM6446 EVM is clocked by U55, as configured by
  45. * board-dm644x-evm.c using GPIOs from U18. There are six
  46. * options; here we "know" we use a 48 KHz sample rate.
  47. */
  48. else if (machine_is_davinci_evm())
  49. sysclk = 12288000;
  50. else if (machine_is_davinci_da830_evm() ||
  51. machine_is_davinci_da850_evm())
  52. sysclk = 24576000;
  53. else
  54. return -EINVAL;
  55. /* set codec DAI configuration */
  56. ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT);
  57. if (ret < 0)
  58. return ret;
  59. /* set cpu DAI configuration */
  60. ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
  61. if (ret < 0)
  62. return ret;
  63. /* set the codec system clock */
  64. ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
  65. if (ret < 0)
  66. return ret;
  67. return 0;
  68. }
  69. static int evm_spdif_hw_params(struct snd_pcm_substream *substream,
  70. struct snd_pcm_hw_params *params)
  71. {
  72. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  73. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  74. /* set cpu DAI configuration */
  75. return snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
  76. }
  77. static struct snd_soc_ops evm_ops = {
  78. .hw_params = evm_hw_params,
  79. };
  80. static struct snd_soc_ops evm_spdif_ops = {
  81. .hw_params = evm_spdif_hw_params,
  82. };
  83. /* davinci-evm machine dapm widgets */
  84. static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
  85. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  86. SND_SOC_DAPM_LINE("Line Out", NULL),
  87. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  88. SND_SOC_DAPM_LINE("Line In", NULL),
  89. };
  90. /* davinci-evm machine audio_mapnections to the codec pins */
  91. static const struct snd_soc_dapm_route audio_map[] = {
  92. /* Headphone connected to HPLOUT, HPROUT */
  93. {"Headphone Jack", NULL, "HPLOUT"},
  94. {"Headphone Jack", NULL, "HPROUT"},
  95. /* Line Out connected to LLOUT, RLOUT */
  96. {"Line Out", NULL, "LLOUT"},
  97. {"Line Out", NULL, "RLOUT"},
  98. /* Mic connected to (MIC3L | MIC3R) */
  99. {"MIC3L", NULL, "Mic Bias 2V"},
  100. {"MIC3R", NULL, "Mic Bias 2V"},
  101. {"Mic Bias 2V", NULL, "Mic Jack"},
  102. /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
  103. {"LINE1L", NULL, "Line In"},
  104. {"LINE2L", NULL, "Line In"},
  105. {"LINE1R", NULL, "Line In"},
  106. {"LINE2R", NULL, "Line In"},
  107. };
  108. /* Logic for a aic3x as connected on a davinci-evm */
  109. static int evm_aic3x_init(struct snd_soc_pcm_runtime *rtd)
  110. {
  111. struct snd_soc_codec *codec = rtd->codec;
  112. struct snd_soc_dapm_context *dapm = &codec->dapm;
  113. /* Add davinci-evm specific widgets */
  114. snd_soc_dapm_new_controls(dapm, aic3x_dapm_widgets,
  115. ARRAY_SIZE(aic3x_dapm_widgets));
  116. /* Set up davinci-evm specific audio path audio_map */
  117. snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
  118. /* not connected */
  119. snd_soc_dapm_disable_pin(dapm, "MONO_LOUT");
  120. snd_soc_dapm_disable_pin(dapm, "HPLCOM");
  121. snd_soc_dapm_disable_pin(dapm, "HPRCOM");
  122. /* always connected */
  123. snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
  124. snd_soc_dapm_enable_pin(dapm, "Line Out");
  125. snd_soc_dapm_enable_pin(dapm, "Mic Jack");
  126. snd_soc_dapm_enable_pin(dapm, "Line In");
  127. snd_soc_dapm_sync(dapm);
  128. return 0;
  129. }
  130. /* davinci-evm digital audio interface glue - connects codec <--> CPU */
  131. static struct snd_soc_dai_link evm_dai = {
  132. .name = "TLV320AIC3X",
  133. .stream_name = "AIC3X",
  134. .cpu_dai_name = "davinci-mcasp.0",
  135. .codec_dai_name = "tlv320aic3x-hifi",
  136. .codec_name = "tlv320aic3x-codec.0-001a",
  137. .platform_name = "davinci-pcm-audio",
  138. .init = evm_aic3x_init,
  139. .ops = &evm_ops,
  140. };
  141. static struct snd_soc_dai_link dm365_evm_dai = {
  142. #ifdef CONFIG_SND_DM365_AIC3X_CODEC
  143. .name = "TLV320AIC3X",
  144. .stream_name = "AIC3X",
  145. .cpu_dai_name = "davinci-i2s",
  146. .codec_dai_name = "tlv320aic3x-hifi",
  147. .init = evm_aic3x_init,
  148. .codec_name = "tlv320aic3x-codec.0-001a",
  149. .ops = &evm_ops,
  150. #elif defined(CONFIG_SND_DM365_VOICE_CODEC)
  151. .name = "Voice Codec - CQ93VC",
  152. .stream_name = "CQ93",
  153. .cpu_dai_name = "davinci-vcif",
  154. .codec_dai_name = "cq93vc-hifi",
  155. .codec_name = "cq93vc-codec",
  156. #endif
  157. .platform_name = "davinci-pcm-audio",
  158. };
  159. static struct snd_soc_dai_link dm6467_evm_dai[] = {
  160. {
  161. .name = "TLV320AIC3X",
  162. .stream_name = "AIC3X",
  163. .cpu_dai_name= "davinci-mcasp.0",
  164. .codec_dai_name = "tlv320aic3x-hifi",
  165. .platform_name ="davinci-pcm-audio",
  166. .codec_name = "tlv320aic3x-codec.0-001a",
  167. .init = evm_aic3x_init,
  168. .ops = &evm_ops,
  169. },
  170. {
  171. .name = "McASP",
  172. .stream_name = "spdif",
  173. .cpu_dai_name= "davinci-mcasp.1",
  174. .codec_dai_name = "dit-hifi",
  175. .codec_name = "spdif_dit",
  176. .platform_name = "davinci-pcm-audio",
  177. .ops = &evm_spdif_ops,
  178. },
  179. };
  180. static struct snd_soc_dai_link da8xx_evm_dai = {
  181. .name = "TLV320AIC3X",
  182. .stream_name = "AIC3X",
  183. .cpu_dai_name= "davinci-mcasp.0",
  184. .codec_dai_name = "tlv320aic3x-hifi",
  185. .codec_name = "tlv320aic3x-codec.0-001a",
  186. .platform_name = "davinci-pcm-audio",
  187. .init = evm_aic3x_init,
  188. .ops = &evm_ops,
  189. };
  190. /* davinci dm6446, dm355 evm audio machine driver */
  191. static struct snd_soc_card snd_soc_card_evm = {
  192. .name = "DaVinci EVM",
  193. .dai_link = &evm_dai,
  194. .num_links = 1,
  195. };
  196. /* davinci dm365 evm audio machine driver */
  197. static struct snd_soc_card dm365_snd_soc_card_evm = {
  198. .name = "DaVinci DM365 EVM",
  199. .dai_link = &dm365_evm_dai,
  200. .num_links = 1,
  201. };
  202. /* davinci dm6467 evm audio machine driver */
  203. static struct snd_soc_card dm6467_snd_soc_card_evm = {
  204. .name = "DaVinci DM6467 EVM",
  205. .dai_link = dm6467_evm_dai,
  206. .num_links = ARRAY_SIZE(dm6467_evm_dai),
  207. };
  208. static struct snd_soc_card da830_snd_soc_card = {
  209. .name = "DA830/OMAP-L137 EVM",
  210. .dai_link = &da8xx_evm_dai,
  211. .num_links = 1,
  212. };
  213. static struct snd_soc_card da850_snd_soc_card = {
  214. .name = "DA850/OMAP-L138 EVM",
  215. .dai_link = &da8xx_evm_dai,
  216. .num_links = 1,
  217. };
  218. static struct platform_device *evm_snd_device;
  219. static int __init evm_init(void)
  220. {
  221. struct snd_soc_card *evm_snd_dev_data;
  222. int index;
  223. int ret;
  224. if (machine_is_davinci_evm()) {
  225. evm_snd_dev_data = &snd_soc_card_evm;
  226. index = 0;
  227. } else if (machine_is_davinci_dm355_evm()) {
  228. evm_snd_dev_data = &snd_soc_card_evm;
  229. index = 1;
  230. } else if (machine_is_davinci_dm365_evm()) {
  231. evm_snd_dev_data = &dm365_snd_soc_card_evm;
  232. index = 0;
  233. } else if (machine_is_davinci_dm6467_evm()) {
  234. evm_snd_dev_data = &dm6467_snd_soc_card_evm;
  235. index = 0;
  236. } else if (machine_is_davinci_da830_evm()) {
  237. evm_snd_dev_data = &da830_snd_soc_card;
  238. index = 1;
  239. } else if (machine_is_davinci_da850_evm()) {
  240. evm_snd_dev_data = &da850_snd_soc_card;
  241. index = 0;
  242. } else
  243. return -EINVAL;
  244. evm_snd_device = platform_device_alloc("soc-audio", index);
  245. if (!evm_snd_device)
  246. return -ENOMEM;
  247. platform_set_drvdata(evm_snd_device, evm_snd_dev_data);
  248. ret = platform_device_add(evm_snd_device);
  249. if (ret)
  250. platform_device_put(evm_snd_device);
  251. return ret;
  252. }
  253. static void __exit evm_exit(void)
  254. {
  255. platform_device_unregister(evm_snd_device);
  256. }
  257. module_init(evm_init);
  258. module_exit(evm_exit);
  259. MODULE_AUTHOR("Vladimir Barinov");
  260. MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
  261. MODULE_LICENSE("GPL");