davinci-evm.c 8.9 KB

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