davinci-evm.c 9.0 KB

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