davinci-evm.c 8.8 KB

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