davinci-evm.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  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/platform_data/edma.h>
  17. #include <linux/i2c.h>
  18. #include <linux/of_platform.h>
  19. #include <sound/core.h>
  20. #include <sound/pcm.h>
  21. #include <sound/soc.h>
  22. #include <asm/dma.h>
  23. #include <asm/mach-types.h>
  24. #include <linux/edma.h>
  25. #include "davinci-pcm.h"
  26. #include "davinci-i2s.h"
  27. #include "davinci-mcasp.h"
  28. struct snd_soc_card_drvdata_davinci {
  29. unsigned sysclk;
  30. };
  31. #define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
  32. SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF)
  33. static int evm_hw_params(struct snd_pcm_substream *substream,
  34. struct snd_pcm_hw_params *params)
  35. {
  36. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  37. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  38. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  39. struct snd_soc_codec *codec = rtd->codec;
  40. struct snd_soc_card *soc_card = codec->card;
  41. int ret = 0;
  42. unsigned sysclk = ((struct snd_soc_card_drvdata_davinci *)
  43. snd_soc_card_get_drvdata(soc_card))->sysclk;
  44. /* set codec DAI configuration */
  45. ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT);
  46. if (ret < 0)
  47. return ret;
  48. /* set cpu DAI configuration */
  49. ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
  50. if (ret < 0)
  51. return ret;
  52. /* set the codec system clock */
  53. ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
  54. if (ret < 0)
  55. return ret;
  56. /* set the CPU system clock */
  57. ret = snd_soc_dai_set_sysclk(cpu_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
  58. if (ret < 0)
  59. return ret;
  60. return 0;
  61. }
  62. static int evm_spdif_hw_params(struct snd_pcm_substream *substream,
  63. struct snd_pcm_hw_params *params)
  64. {
  65. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  66. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  67. /* set cpu DAI configuration */
  68. return snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
  69. }
  70. static struct snd_soc_ops evm_ops = {
  71. .hw_params = evm_hw_params,
  72. };
  73. static struct snd_soc_ops evm_spdif_ops = {
  74. .hw_params = evm_spdif_hw_params,
  75. };
  76. /* davinci-evm machine dapm widgets */
  77. static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
  78. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  79. SND_SOC_DAPM_LINE("Line Out", NULL),
  80. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  81. SND_SOC_DAPM_LINE("Line In", NULL),
  82. };
  83. /* davinci-evm machine audio_mapnections to the codec pins */
  84. static const struct snd_soc_dapm_route audio_map[] = {
  85. /* Headphone connected to HPLOUT, HPROUT */
  86. {"Headphone Jack", NULL, "HPLOUT"},
  87. {"Headphone Jack", NULL, "HPROUT"},
  88. /* Line Out connected to LLOUT, RLOUT */
  89. {"Line Out", NULL, "LLOUT"},
  90. {"Line Out", NULL, "RLOUT"},
  91. /* Mic connected to (MIC3L | MIC3R) */
  92. {"MIC3L", NULL, "Mic Bias"},
  93. {"MIC3R", NULL, "Mic Bias"},
  94. {"Mic Bias", NULL, "Mic Jack"},
  95. /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
  96. {"LINE1L", NULL, "Line In"},
  97. {"LINE2L", NULL, "Line In"},
  98. {"LINE1R", NULL, "Line In"},
  99. {"LINE2R", NULL, "Line In"},
  100. };
  101. /* Logic for a aic3x as connected on a davinci-evm */
  102. static int evm_aic3x_init(struct snd_soc_pcm_runtime *rtd)
  103. {
  104. struct snd_soc_codec *codec = rtd->codec;
  105. struct snd_soc_dapm_context *dapm = &codec->dapm;
  106. struct device_node *np = codec->card->dev->of_node;
  107. int ret;
  108. /* Add davinci-evm specific widgets */
  109. snd_soc_dapm_new_controls(dapm, aic3x_dapm_widgets,
  110. ARRAY_SIZE(aic3x_dapm_widgets));
  111. if (np) {
  112. ret = snd_soc_of_parse_audio_routing(codec->card,
  113. "ti,audio-routing");
  114. if (ret)
  115. return ret;
  116. } else {
  117. /* Set up davinci-evm specific audio path audio_map */
  118. snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
  119. }
  120. /* not connected */
  121. snd_soc_dapm_disable_pin(dapm, "MONO_LOUT");
  122. snd_soc_dapm_disable_pin(dapm, "HPLCOM");
  123. snd_soc_dapm_disable_pin(dapm, "HPRCOM");
  124. /* always connected */
  125. snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
  126. snd_soc_dapm_enable_pin(dapm, "Line Out");
  127. snd_soc_dapm_enable_pin(dapm, "Mic Jack");
  128. snd_soc_dapm_enable_pin(dapm, "Line In");
  129. return 0;
  130. }
  131. /* davinci-evm digital audio interface glue - connects codec <--> CPU */
  132. static struct snd_soc_dai_link dm6446_evm_dai = {
  133. .name = "TLV320AIC3X",
  134. .stream_name = "AIC3X",
  135. .cpu_dai_name = "davinci-mcbsp",
  136. .codec_dai_name = "tlv320aic3x-hifi",
  137. .codec_name = "tlv320aic3x-codec.1-001b",
  138. .platform_name = "davinci-mcbsp",
  139. .init = evm_aic3x_init,
  140. .ops = &evm_ops,
  141. };
  142. static struct snd_soc_dai_link dm355_evm_dai = {
  143. .name = "TLV320AIC3X",
  144. .stream_name = "AIC3X",
  145. .cpu_dai_name = "davinci-mcbsp.1",
  146. .codec_dai_name = "tlv320aic3x-hifi",
  147. .codec_name = "tlv320aic3x-codec.1-001b",
  148. .platform_name = "davinci-mcbsp.1",
  149. .init = evm_aic3x_init,
  150. .ops = &evm_ops,
  151. };
  152. static struct snd_soc_dai_link dm365_evm_dai = {
  153. #ifdef CONFIG_SND_DM365_AIC3X_CODEC
  154. .name = "TLV320AIC3X",
  155. .stream_name = "AIC3X",
  156. .cpu_dai_name = "davinci-mcbsp",
  157. .codec_dai_name = "tlv320aic3x-hifi",
  158. .init = evm_aic3x_init,
  159. .codec_name = "tlv320aic3x-codec.1-0018",
  160. .ops = &evm_ops,
  161. .platform_name = "davinci-mcbsp",
  162. #elif defined(CONFIG_SND_DM365_VOICE_CODEC)
  163. .name = "Voice Codec - CQ93VC",
  164. .stream_name = "CQ93",
  165. .cpu_dai_name = "davinci-vcif",
  166. .codec_dai_name = "cq93vc-hifi",
  167. .codec_name = "cq93vc-codec",
  168. .platform_name = "davinci-vcif",
  169. #endif
  170. };
  171. static struct snd_soc_dai_link dm6467_evm_dai[] = {
  172. {
  173. .name = "TLV320AIC3X",
  174. .stream_name = "AIC3X",
  175. .cpu_dai_name= "davinci-mcasp.0",
  176. .codec_dai_name = "tlv320aic3x-hifi",
  177. .platform_name = "davinci-mcasp.0",
  178. .codec_name = "tlv320aic3x-codec.0-001a",
  179. .init = evm_aic3x_init,
  180. .ops = &evm_ops,
  181. },
  182. {
  183. .name = "McASP",
  184. .stream_name = "spdif",
  185. .cpu_dai_name= "davinci-mcasp.1",
  186. .codec_dai_name = "dit-hifi",
  187. .codec_name = "spdif_dit",
  188. .platform_name = "davinci-mcasp.1",
  189. .ops = &evm_spdif_ops,
  190. },
  191. };
  192. static struct snd_soc_dai_link da830_evm_dai = {
  193. .name = "TLV320AIC3X",
  194. .stream_name = "AIC3X",
  195. .cpu_dai_name = "davinci-mcasp.1",
  196. .codec_dai_name = "tlv320aic3x-hifi",
  197. .codec_name = "tlv320aic3x-codec.1-0018",
  198. .platform_name = "davinci-mcasp.1",
  199. .init = evm_aic3x_init,
  200. .ops = &evm_ops,
  201. };
  202. static struct snd_soc_dai_link da850_evm_dai = {
  203. .name = "TLV320AIC3X",
  204. .stream_name = "AIC3X",
  205. .cpu_dai_name= "davinci-mcasp.0",
  206. .codec_dai_name = "tlv320aic3x-hifi",
  207. .codec_name = "tlv320aic3x-codec.1-0018",
  208. .platform_name = "davinci-mcasp.0",
  209. .init = evm_aic3x_init,
  210. .ops = &evm_ops,
  211. };
  212. /* davinci dm6446 evm audio machine driver */
  213. /*
  214. * ASP0 in DM6446 EVM is clocked by U55, as configured by
  215. * board-dm644x-evm.c using GPIOs from U18. There are six
  216. * options; here we "know" we use a 48 KHz sample rate.
  217. */
  218. static struct snd_soc_card_drvdata_davinci dm6446_snd_soc_card_drvdata = {
  219. .sysclk = 12288000,
  220. };
  221. static struct snd_soc_card dm6446_snd_soc_card_evm = {
  222. .name = "DaVinci DM6446 EVM",
  223. .owner = THIS_MODULE,
  224. .dai_link = &dm6446_evm_dai,
  225. .num_links = 1,
  226. .drvdata = &dm6446_snd_soc_card_drvdata,
  227. };
  228. /* davinci dm355 evm audio machine driver */
  229. /* ASP1 on DM355 EVM is clocked by an external oscillator */
  230. static struct snd_soc_card_drvdata_davinci dm355_snd_soc_card_drvdata = {
  231. .sysclk = 27000000,
  232. };
  233. static struct snd_soc_card dm355_snd_soc_card_evm = {
  234. .name = "DaVinci DM355 EVM",
  235. .owner = THIS_MODULE,
  236. .dai_link = &dm355_evm_dai,
  237. .num_links = 1,
  238. .drvdata = &dm355_snd_soc_card_drvdata,
  239. };
  240. /* davinci dm365 evm audio machine driver */
  241. static struct snd_soc_card_drvdata_davinci dm365_snd_soc_card_drvdata = {
  242. .sysclk = 27000000,
  243. };
  244. static struct snd_soc_card dm365_snd_soc_card_evm = {
  245. .name = "DaVinci DM365 EVM",
  246. .owner = THIS_MODULE,
  247. .dai_link = &dm365_evm_dai,
  248. .num_links = 1,
  249. .drvdata = &dm365_snd_soc_card_drvdata,
  250. };
  251. /* davinci dm6467 evm audio machine driver */
  252. static struct snd_soc_card_drvdata_davinci dm6467_snd_soc_card_drvdata = {
  253. .sysclk = 27000000,
  254. };
  255. static struct snd_soc_card dm6467_snd_soc_card_evm = {
  256. .name = "DaVinci DM6467 EVM",
  257. .owner = THIS_MODULE,
  258. .dai_link = dm6467_evm_dai,
  259. .num_links = ARRAY_SIZE(dm6467_evm_dai),
  260. .drvdata = &dm6467_snd_soc_card_drvdata,
  261. };
  262. static struct snd_soc_card_drvdata_davinci da830_snd_soc_card_drvdata = {
  263. .sysclk = 24576000,
  264. };
  265. static struct snd_soc_card da830_snd_soc_card = {
  266. .name = "DA830/OMAP-L137 EVM",
  267. .owner = THIS_MODULE,
  268. .dai_link = &da830_evm_dai,
  269. .num_links = 1,
  270. .drvdata = &da830_snd_soc_card_drvdata,
  271. };
  272. static struct snd_soc_card_drvdata_davinci da850_snd_soc_card_drvdata = {
  273. .sysclk = 24576000,
  274. };
  275. static struct snd_soc_card da850_snd_soc_card = {
  276. .name = "DA850/OMAP-L138 EVM",
  277. .owner = THIS_MODULE,
  278. .dai_link = &da850_evm_dai,
  279. .num_links = 1,
  280. .drvdata = &da850_snd_soc_card_drvdata,
  281. };
  282. #if defined(CONFIG_OF)
  283. /*
  284. * The struct is used as place holder. It will be completely
  285. * filled with data from dt node.
  286. */
  287. static struct snd_soc_dai_link evm_dai_tlv320aic3x = {
  288. .name = "TLV320AIC3X",
  289. .stream_name = "AIC3X",
  290. .codec_dai_name = "tlv320aic3x-hifi",
  291. .ops = &evm_ops,
  292. .init = evm_aic3x_init,
  293. };
  294. static const struct of_device_id davinci_evm_dt_ids[] = {
  295. {
  296. .compatible = "ti,da830-evm-audio",
  297. .data = (void *) &evm_dai_tlv320aic3x,
  298. },
  299. { /* sentinel */ }
  300. };
  301. MODULE_DEVICE_TABLE(of, davinci_evm_dt_ids);
  302. /* davinci evm audio machine driver */
  303. static struct snd_soc_card evm_soc_card = {
  304. .owner = THIS_MODULE,
  305. .num_links = 1,
  306. };
  307. static int davinci_evm_probe(struct platform_device *pdev)
  308. {
  309. struct device_node *np = pdev->dev.of_node;
  310. const struct of_device_id *match =
  311. of_match_device(of_match_ptr(davinci_evm_dt_ids), &pdev->dev);
  312. struct snd_soc_dai_link *dai = (struct snd_soc_dai_link *) match->data;
  313. struct snd_soc_card_drvdata_davinci *drvdata = NULL;
  314. int ret = 0;
  315. evm_soc_card.dai_link = dai;
  316. dai->codec_of_node = of_parse_phandle(np, "ti,audio-codec", 0);
  317. if (!dai->codec_of_node)
  318. return -EINVAL;
  319. dai->cpu_of_node = of_parse_phandle(np, "ti,mcasp-controller", 0);
  320. if (!dai->cpu_of_node)
  321. return -EINVAL;
  322. dai->platform_of_node = dai->cpu_of_node;
  323. evm_soc_card.dev = &pdev->dev;
  324. ret = snd_soc_of_parse_card_name(&evm_soc_card, "ti,model");
  325. if (ret)
  326. return ret;
  327. drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL);
  328. if (!drvdata)
  329. return -ENOMEM;
  330. ret = of_property_read_u32(np, "ti,codec-clock-rate", &drvdata->sysclk);
  331. if (ret < 0)
  332. return -EINVAL;
  333. snd_soc_card_set_drvdata(&evm_soc_card, drvdata);
  334. ret = devm_snd_soc_register_card(&pdev->dev, &evm_soc_card);
  335. if (ret)
  336. dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
  337. return ret;
  338. }
  339. static int davinci_evm_remove(struct platform_device *pdev)
  340. {
  341. struct snd_soc_card *card = platform_get_drvdata(pdev);
  342. snd_soc_unregister_card(card);
  343. return 0;
  344. }
  345. static struct platform_driver davinci_evm_driver = {
  346. .probe = davinci_evm_probe,
  347. .remove = davinci_evm_remove,
  348. .driver = {
  349. .name = "davinci_evm",
  350. .owner = THIS_MODULE,
  351. .of_match_table = of_match_ptr(davinci_evm_dt_ids),
  352. },
  353. };
  354. #endif
  355. static struct platform_device *evm_snd_device;
  356. static int __init evm_init(void)
  357. {
  358. struct snd_soc_card *evm_snd_dev_data;
  359. int index;
  360. int ret;
  361. /*
  362. * If dtb is there, the devices will be created dynamically.
  363. * Only register platfrom driver structure.
  364. */
  365. #if defined(CONFIG_OF)
  366. if (of_have_populated_dt())
  367. return platform_driver_register(&davinci_evm_driver);
  368. #endif
  369. if (machine_is_davinci_evm()) {
  370. evm_snd_dev_data = &dm6446_snd_soc_card_evm;
  371. index = 0;
  372. } else if (machine_is_davinci_dm355_evm()) {
  373. evm_snd_dev_data = &dm355_snd_soc_card_evm;
  374. index = 1;
  375. } else if (machine_is_davinci_dm365_evm()) {
  376. evm_snd_dev_data = &dm365_snd_soc_card_evm;
  377. index = 0;
  378. } else if (machine_is_davinci_dm6467_evm()) {
  379. evm_snd_dev_data = &dm6467_snd_soc_card_evm;
  380. index = 0;
  381. } else if (machine_is_davinci_da830_evm()) {
  382. evm_snd_dev_data = &da830_snd_soc_card;
  383. index = 1;
  384. } else if (machine_is_davinci_da850_evm()) {
  385. evm_snd_dev_data = &da850_snd_soc_card;
  386. index = 0;
  387. } else
  388. return -EINVAL;
  389. evm_snd_device = platform_device_alloc("soc-audio", index);
  390. if (!evm_snd_device)
  391. return -ENOMEM;
  392. platform_set_drvdata(evm_snd_device, evm_snd_dev_data);
  393. ret = platform_device_add(evm_snd_device);
  394. if (ret)
  395. platform_device_put(evm_snd_device);
  396. return ret;
  397. }
  398. static void __exit evm_exit(void)
  399. {
  400. #if defined(CONFIG_OF)
  401. if (of_have_populated_dt()) {
  402. platform_driver_unregister(&davinci_evm_driver);
  403. return;
  404. }
  405. #endif
  406. platform_device_unregister(evm_snd_device);
  407. }
  408. module_init(evm_init);
  409. module_exit(evm_exit);
  410. MODULE_AUTHOR("Vladimir Barinov");
  411. MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
  412. MODULE_LICENSE("GPL");