davinci-evm.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. /* Add davinci-evm specific widgets */
  113. snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets,
  114. ARRAY_SIZE(aic3x_dapm_widgets));
  115. /* Set up davinci-evm specific audio path audio_map */
  116. snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
  117. /* not connected */
  118. snd_soc_dapm_disable_pin(codec, "MONO_LOUT");
  119. snd_soc_dapm_disable_pin(codec, "HPLCOM");
  120. snd_soc_dapm_disable_pin(codec, "HPRCOM");
  121. /* always connected */
  122. snd_soc_dapm_enable_pin(codec, "Headphone Jack");
  123. snd_soc_dapm_enable_pin(codec, "Line Out");
  124. snd_soc_dapm_enable_pin(codec, "Mic Jack");
  125. snd_soc_dapm_enable_pin(codec, "Line In");
  126. snd_soc_dapm_sync(codec);
  127. return 0;
  128. }
  129. /* davinci-evm digital audio interface glue - connects codec <--> CPU */
  130. static struct snd_soc_dai_link dm6446_evm_dai = {
  131. .name = "TLV320AIC3X",
  132. .stream_name = "AIC3X",
  133. .cpu_dai_name = "davinci-mcbsp",
  134. .codec_dai_name = "tlv320aic3x-hifi",
  135. .codec_name = "tlv320aic3x-codec.1-001b",
  136. .platform_name = "davinci-pcm-audio",
  137. .init = evm_aic3x_init,
  138. .ops = &evm_ops,
  139. };
  140. static struct snd_soc_dai_link dm355_evm_dai = {
  141. .name = "TLV320AIC3X",
  142. .stream_name = "AIC3X",
  143. .cpu_dai_name = "davinci-mcbsp.1",
  144. .codec_dai_name = "tlv320aic3x-hifi",
  145. .codec_name = "tlv320aic3x-codec.1-001b",
  146. .platform_name = "davinci-pcm-audio",
  147. .init = evm_aic3x_init,
  148. .ops = &evm_ops,
  149. };
  150. static struct snd_soc_dai_link dm365_evm_dai = {
  151. #ifdef CONFIG_SND_DM365_AIC3X_CODEC
  152. .name = "TLV320AIC3X",
  153. .stream_name = "AIC3X",
  154. .cpu_dai_name = "davinci-mcbsp",
  155. .codec_dai_name = "tlv320aic3x-hifi",
  156. .init = evm_aic3x_init,
  157. .codec_name = "tlv320aic3x-codec.1-0018",
  158. .ops = &evm_ops,
  159. #elif defined(CONFIG_SND_DM365_VOICE_CODEC)
  160. .name = "Voice Codec - CQ93VC",
  161. .stream_name = "CQ93",
  162. .cpu_dai_name = "davinci-vcif",
  163. .codec_dai_name = "cq93vc-hifi",
  164. .codec_name = "cq93vc-codec",
  165. #endif
  166. .platform_name = "davinci-pcm-audio",
  167. };
  168. static struct snd_soc_dai_link dm6467_evm_dai[] = {
  169. {
  170. .name = "TLV320AIC3X",
  171. .stream_name = "AIC3X",
  172. .cpu_dai_name= "davinci-mcasp.0",
  173. .codec_dai_name = "tlv320aic3x-hifi",
  174. .platform_name ="davinci-pcm-audio",
  175. .codec_name = "tlv320aic3x-codec.0-001a",
  176. .init = evm_aic3x_init,
  177. .ops = &evm_ops,
  178. },
  179. {
  180. .name = "McASP",
  181. .stream_name = "spdif",
  182. .cpu_dai_name= "davinci-mcasp.1",
  183. .codec_dai_name = "dit-hifi",
  184. .codec_name = "spdif_dit",
  185. .platform_name = "davinci-pcm-audio",
  186. .ops = &evm_spdif_ops,
  187. },
  188. };
  189. static struct snd_soc_dai_link da8xx_evm_dai = {
  190. .name = "TLV320AIC3X",
  191. .stream_name = "AIC3X",
  192. .cpu_dai_name= "davinci-mcasp.0",
  193. .codec_dai_name = "tlv320aic3x-hifi",
  194. .codec_name = "tlv320aic3x-codec.0-001a",
  195. .platform_name = "davinci-pcm-audio",
  196. .init = evm_aic3x_init,
  197. .ops = &evm_ops,
  198. };
  199. /* davinci dm6446 evm audio machine driver */
  200. static struct snd_soc_card dm6446_snd_soc_card_evm = {
  201. .name = "DaVinci DM6446 EVM",
  202. .dai_link = &dm6446_evm_dai,
  203. .num_links = 1,
  204. };
  205. /* davinci dm355 evm audio machine driver */
  206. static struct snd_soc_card dm355_snd_soc_card_evm = {
  207. .name = "DaVinci DM355 EVM",
  208. .dai_link = &dm355_evm_dai,
  209. .num_links = 1,
  210. };
  211. /* davinci dm365 evm audio machine driver */
  212. static struct snd_soc_card dm365_snd_soc_card_evm = {
  213. .name = "DaVinci DM365 EVM",
  214. .dai_link = &dm365_evm_dai,
  215. .num_links = 1,
  216. };
  217. /* davinci dm6467 evm audio machine driver */
  218. static struct snd_soc_card dm6467_snd_soc_card_evm = {
  219. .name = "DaVinci DM6467 EVM",
  220. .dai_link = dm6467_evm_dai,
  221. .num_links = ARRAY_SIZE(dm6467_evm_dai),
  222. };
  223. static struct snd_soc_card da830_snd_soc_card = {
  224. .name = "DA830/OMAP-L137 EVM",
  225. .dai_link = &da8xx_evm_dai,
  226. .num_links = 1,
  227. };
  228. static struct snd_soc_card da850_snd_soc_card = {
  229. .name = "DA850/OMAP-L138 EVM",
  230. .dai_link = &da8xx_evm_dai,
  231. .num_links = 1,
  232. };
  233. static struct platform_device *evm_snd_device;
  234. static int __init evm_init(void)
  235. {
  236. struct snd_soc_card *evm_snd_dev_data;
  237. int index;
  238. int ret;
  239. if (machine_is_davinci_evm()) {
  240. evm_snd_dev_data = &dm6446_snd_soc_card_evm;
  241. index = 0;
  242. } else if (machine_is_davinci_dm355_evm()) {
  243. evm_snd_dev_data = &dm355_snd_soc_card_evm;
  244. index = 1;
  245. } else if (machine_is_davinci_dm365_evm()) {
  246. evm_snd_dev_data = &dm365_snd_soc_card_evm;
  247. index = 0;
  248. } else if (machine_is_davinci_dm6467_evm()) {
  249. evm_snd_dev_data = &dm6467_snd_soc_card_evm;
  250. index = 0;
  251. } else if (machine_is_davinci_da830_evm()) {
  252. evm_snd_dev_data = &da830_snd_soc_card;
  253. index = 1;
  254. } else if (machine_is_davinci_da850_evm()) {
  255. evm_snd_dev_data = &da850_snd_soc_card;
  256. index = 0;
  257. } else
  258. return -EINVAL;
  259. evm_snd_device = platform_device_alloc("soc-audio", index);
  260. if (!evm_snd_device)
  261. return -ENOMEM;
  262. platform_set_drvdata(evm_snd_device, evm_snd_dev_data);
  263. ret = platform_device_add(evm_snd_device);
  264. if (ret)
  265. platform_device_put(evm_snd_device);
  266. return ret;
  267. }
  268. static void __exit evm_exit(void)
  269. {
  270. platform_device_unregister(evm_snd_device);
  271. }
  272. module_init(evm_init);
  273. module_exit(evm_exit);
  274. MODULE_AUTHOR("Vladimir Barinov");
  275. MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
  276. MODULE_LICENSE("GPL");