davinci-evm.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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 <sound/core.h>
  17. #include <sound/pcm.h>
  18. #include <sound/soc.h>
  19. #include <sound/soc-dapm.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 "../codecs/tlv320aic3x.h"
  26. #include "davinci-pcm.h"
  27. #include "davinci-i2s.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->dai->codec_dai;
  35. struct snd_soc_dai *cpu_dai = rtd->dai->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())
  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
  48. return -EINVAL;
  49. /* set codec DAI configuration */
  50. ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT);
  51. if (ret < 0)
  52. return ret;
  53. /* set cpu DAI configuration */
  54. ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
  55. if (ret < 0)
  56. return ret;
  57. /* set the codec system clock */
  58. ret = snd_soc_dai_set_sysclk(codec_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
  59. if (ret < 0)
  60. return ret;
  61. return 0;
  62. }
  63. static struct snd_soc_ops evm_ops = {
  64. .hw_params = evm_hw_params,
  65. };
  66. /* davinci-evm machine dapm widgets */
  67. static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
  68. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  69. SND_SOC_DAPM_LINE("Line Out", NULL),
  70. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  71. SND_SOC_DAPM_LINE("Line In", NULL),
  72. };
  73. /* davinci-evm machine audio_mapnections to the codec pins */
  74. static const struct snd_soc_dapm_route audio_map[] = {
  75. /* Headphone connected to HPLOUT, HPROUT */
  76. {"Headphone Jack", NULL, "HPLOUT"},
  77. {"Headphone Jack", NULL, "HPROUT"},
  78. /* Line Out connected to LLOUT, RLOUT */
  79. {"Line Out", NULL, "LLOUT"},
  80. {"Line Out", NULL, "RLOUT"},
  81. /* Mic connected to (MIC3L | MIC3R) */
  82. {"MIC3L", NULL, "Mic Bias 2V"},
  83. {"MIC3R", NULL, "Mic Bias 2V"},
  84. {"Mic Bias 2V", NULL, "Mic Jack"},
  85. /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
  86. {"LINE1L", NULL, "Line In"},
  87. {"LINE2L", NULL, "Line In"},
  88. {"LINE1R", NULL, "Line In"},
  89. {"LINE2R", NULL, "Line In"},
  90. };
  91. /* Logic for a aic3x as connected on a davinci-evm */
  92. static int evm_aic3x_init(struct snd_soc_codec *codec)
  93. {
  94. /* Add davinci-evm specific widgets */
  95. snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets,
  96. ARRAY_SIZE(aic3x_dapm_widgets));
  97. /* Set up davinci-evm specific audio path audio_map */
  98. snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
  99. /* not connected */
  100. snd_soc_dapm_disable_pin(codec, "MONO_LOUT");
  101. snd_soc_dapm_disable_pin(codec, "HPLCOM");
  102. snd_soc_dapm_disable_pin(codec, "HPRCOM");
  103. /* always connected */
  104. snd_soc_dapm_enable_pin(codec, "Headphone Jack");
  105. snd_soc_dapm_enable_pin(codec, "Line Out");
  106. snd_soc_dapm_enable_pin(codec, "Mic Jack");
  107. snd_soc_dapm_enable_pin(codec, "Line In");
  108. snd_soc_dapm_sync(codec);
  109. return 0;
  110. }
  111. /* davinci-evm digital audio interface glue - connects codec <--> CPU */
  112. static struct snd_soc_dai_link evm_dai = {
  113. .name = "TLV320AIC3X",
  114. .stream_name = "AIC3X",
  115. .cpu_dai = &davinci_i2s_dai,
  116. .codec_dai = &aic3x_dai,
  117. .init = evm_aic3x_init,
  118. .ops = &evm_ops,
  119. };
  120. /* davinci-evm audio machine driver */
  121. static struct snd_soc_card snd_soc_card_evm = {
  122. .name = "DaVinci EVM",
  123. .platform = &davinci_soc_platform,
  124. .dai_link = &evm_dai,
  125. .num_links = 1,
  126. };
  127. /* evm audio private data */
  128. static struct aic3x_setup_data evm_aic3x_setup = {
  129. .i2c_bus = 1,
  130. .i2c_address = 0x1b,
  131. };
  132. /* evm audio subsystem */
  133. static struct snd_soc_device evm_snd_devdata = {
  134. .card = &snd_soc_card_evm,
  135. .codec_dev = &soc_codec_dev_aic3x,
  136. .codec_data = &evm_aic3x_setup,
  137. };
  138. /* DM6446 EVM uses ASP0; line-out is a pair of RCA jacks */
  139. static struct resource evm_snd_resources[] = {
  140. {
  141. .start = DAVINCI_ASP0_BASE,
  142. .end = DAVINCI_ASP0_BASE + SZ_8K - 1,
  143. .flags = IORESOURCE_MEM,
  144. },
  145. };
  146. static struct evm_snd_platform_data evm_snd_data = {
  147. .tx_dma_ch = DAVINCI_DMA_ASP0_TX,
  148. .rx_dma_ch = DAVINCI_DMA_ASP0_RX,
  149. };
  150. /* DM335 EVM uses ASP1; line-out is a stereo mini-jack */
  151. static struct resource dm335evm_snd_resources[] = {
  152. {
  153. .start = DAVINCI_ASP1_BASE,
  154. .end = DAVINCI_ASP1_BASE + SZ_8K - 1,
  155. .flags = IORESOURCE_MEM,
  156. },
  157. };
  158. static struct evm_snd_platform_data dm335evm_snd_data = {
  159. .tx_dma_ch = DAVINCI_DMA_ASP1_TX,
  160. .rx_dma_ch = DAVINCI_DMA_ASP1_RX,
  161. };
  162. static struct platform_device *evm_snd_device;
  163. static int __init evm_init(void)
  164. {
  165. struct resource *resources;
  166. unsigned num_resources;
  167. struct evm_snd_platform_data *data;
  168. int index;
  169. int ret;
  170. if (machine_is_davinci_evm()) {
  171. davinci_cfg_reg(DM644X_MCBSP);
  172. resources = evm_snd_resources;
  173. num_resources = ARRAY_SIZE(evm_snd_resources);
  174. data = &evm_snd_data;
  175. index = 0;
  176. } else if (machine_is_davinci_dm355_evm()) {
  177. /* we don't use ASP1 IRQs, or we'd need to mux them ... */
  178. davinci_cfg_reg(DM355_EVT8_ASP1_TX);
  179. davinci_cfg_reg(DM355_EVT9_ASP1_RX);
  180. resources = dm335evm_snd_resources;
  181. num_resources = ARRAY_SIZE(dm335evm_snd_resources);
  182. data = &dm335evm_snd_data;
  183. index = 1;
  184. } else
  185. return -EINVAL;
  186. evm_snd_device = platform_device_alloc("soc-audio", index);
  187. if (!evm_snd_device)
  188. return -ENOMEM;
  189. platform_set_drvdata(evm_snd_device, &evm_snd_devdata);
  190. evm_snd_devdata.dev = &evm_snd_device->dev;
  191. platform_device_add_data(evm_snd_device, data, sizeof(*data));
  192. ret = platform_device_add_resources(evm_snd_device, resources,
  193. num_resources);
  194. if (ret) {
  195. platform_device_put(evm_snd_device);
  196. return ret;
  197. }
  198. ret = platform_device_add(evm_snd_device);
  199. if (ret)
  200. platform_device_put(evm_snd_device);
  201. return ret;
  202. }
  203. static void __exit evm_exit(void)
  204. {
  205. platform_device_unregister(evm_snd_device);
  206. }
  207. module_init(evm_init);
  208. module_exit(evm_exit);
  209. MODULE_AUTHOR("Vladimir Barinov");
  210. MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
  211. MODULE_LICENSE("GPL");