am3517evm.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * am3517evm.c -- ALSA SoC support for OMAP3517 / AM3517 EVM
  3. *
  4. * Author: Anuj Aggarwal <anuj.aggarwal@ti.com>
  5. *
  6. * Based on sound/soc/omap/beagle.c by Steve Sakoman
  7. *
  8. * Copyright (C) 2009 Texas Instruments Incorporated
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation version 2.
  13. *
  14. * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
  15. * whether express or implied; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. */
  19. #include <linux/clk.h>
  20. #include <linux/platform_device.h>
  21. #include <sound/core.h>
  22. #include <sound/pcm.h>
  23. #include <sound/soc.h>
  24. #include <sound/soc-dapm.h>
  25. #include <asm/mach-types.h>
  26. #include <mach/hardware.h>
  27. #include <mach/gpio.h>
  28. #include <plat/mcbsp.h>
  29. #include "omap-mcbsp.h"
  30. #include "omap-pcm.h"
  31. #include "../codecs/tlv320aic23.h"
  32. #define CODEC_CLOCK 12000000
  33. static int am3517evm_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->dai->codec_dai;
  38. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  39. int ret;
  40. /* Set codec DAI configuration */
  41. ret = snd_soc_dai_set_fmt(codec_dai,
  42. SND_SOC_DAIFMT_DSP_B |
  43. SND_SOC_DAIFMT_NB_NF |
  44. SND_SOC_DAIFMT_CBM_CFM);
  45. if (ret < 0) {
  46. printk(KERN_ERR "can't set codec DAI configuration\n");
  47. return ret;
  48. }
  49. /* Set cpu DAI configuration */
  50. ret = snd_soc_dai_set_fmt(cpu_dai,
  51. SND_SOC_DAIFMT_DSP_B |
  52. SND_SOC_DAIFMT_NB_NF |
  53. SND_SOC_DAIFMT_CBM_CFM);
  54. if (ret < 0) {
  55. printk(KERN_ERR "can't set cpu DAI configuration\n");
  56. return ret;
  57. }
  58. /* Set the codec system clock for DAC and ADC */
  59. ret = snd_soc_dai_set_sysclk(codec_dai, 0,
  60. CODEC_CLOCK, SND_SOC_CLOCK_IN);
  61. if (ret < 0) {
  62. printk(KERN_ERR "can't set codec system clock\n");
  63. return ret;
  64. }
  65. ret = snd_soc_dai_set_sysclk(cpu_dai, OMAP_MCBSP_CLKR_SRC_CLKX, 0,
  66. SND_SOC_CLOCK_IN);
  67. if (ret < 0) {
  68. printk(KERN_ERR "can't set CPU system clock OMAP_MCBSP_CLKR_SRC_CLKX\n");
  69. return ret;
  70. }
  71. snd_soc_dai_set_sysclk(cpu_dai, OMAP_MCBSP_FSR_SRC_FSX, 0,
  72. SND_SOC_CLOCK_IN);
  73. if (ret < 0) {
  74. printk(KERN_ERR "can't set CPU system clock OMAP_MCBSP_FSR_SRC_FSX\n");
  75. return ret;
  76. }
  77. return 0;
  78. }
  79. static struct snd_soc_ops am3517evm_ops = {
  80. .hw_params = am3517evm_hw_params,
  81. };
  82. /* am3517evm machine dapm widgets */
  83. static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = {
  84. SND_SOC_DAPM_HP("Line Out", NULL),
  85. SND_SOC_DAPM_LINE("Line In", NULL),
  86. SND_SOC_DAPM_MIC("Mic In", NULL),
  87. };
  88. static const struct snd_soc_dapm_route audio_map[] = {
  89. /* Line Out connected to LLOUT, RLOUT */
  90. {"Line Out", NULL, "LOUT"},
  91. {"Line Out", NULL, "ROUT"},
  92. {"LLINEIN", NULL, "Line In"},
  93. {"RLINEIN", NULL, "Line In"},
  94. {"MICIN", NULL, "Mic In"},
  95. };
  96. static int am3517evm_aic23_init(struct snd_soc_codec *codec)
  97. {
  98. /* Add am3517-evm specific widgets */
  99. snd_soc_dapm_new_controls(codec, tlv320aic23_dapm_widgets,
  100. ARRAY_SIZE(tlv320aic23_dapm_widgets));
  101. /* Set up davinci-evm specific audio path audio_map */
  102. snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
  103. /* always connected */
  104. snd_soc_dapm_enable_pin(codec, "Line Out");
  105. snd_soc_dapm_enable_pin(codec, "Line In");
  106. snd_soc_dapm_enable_pin(codec, "Mic In");
  107. snd_soc_dapm_sync(codec);
  108. return 0;
  109. }
  110. /* Digital audio interface glue - connects codec <--> CPU */
  111. static struct snd_soc_dai_link am3517evm_dai = {
  112. .name = "TLV320AIC23",
  113. .stream_name = "AIC23",
  114. .cpu_dai = &omap_mcbsp_dai[0],
  115. .codec_dai = &tlv320aic23_dai,
  116. .init = am3517evm_aic23_init,
  117. .ops = &am3517evm_ops,
  118. };
  119. /* Audio machine driver */
  120. static struct snd_soc_card snd_soc_am3517evm = {
  121. .name = "am3517evm",
  122. .platform = &omap_soc_platform,
  123. .dai_link = &am3517evm_dai,
  124. .num_links = 1,
  125. };
  126. /* Audio subsystem */
  127. static struct snd_soc_device am3517evm_snd_devdata = {
  128. .card = &snd_soc_am3517evm,
  129. .codec_dev = &soc_codec_dev_tlv320aic23,
  130. };
  131. static struct platform_device *am3517evm_snd_device;
  132. static int __init am3517evm_soc_init(void)
  133. {
  134. int ret;
  135. if (!machine_is_omap3517evm()) {
  136. pr_err("Not OMAP3517 / AM3517 EVM!\n");
  137. return -ENODEV;
  138. }
  139. pr_info("OMAP3517 / AM3517 EVM SoC init\n");
  140. am3517evm_snd_device = platform_device_alloc("soc-audio", -1);
  141. if (!am3517evm_snd_device) {
  142. printk(KERN_ERR "Platform device allocation failed\n");
  143. return -ENOMEM;
  144. }
  145. platform_set_drvdata(am3517evm_snd_device, &am3517evm_snd_devdata);
  146. am3517evm_snd_devdata.dev = &am3517evm_snd_device->dev;
  147. *(unsigned int *)am3517evm_dai.cpu_dai->private_data = 0; /* McBSP1 */
  148. ret = platform_device_add(am3517evm_snd_device);
  149. if (ret)
  150. goto err1;
  151. return 0;
  152. err1:
  153. printk(KERN_ERR "Unable to add platform device\n");
  154. platform_device_put(am3517evm_snd_device);
  155. return ret;
  156. }
  157. static void __exit am3517evm_soc_exit(void)
  158. {
  159. platform_device_unregister(am3517evm_snd_device);
  160. }
  161. module_init(am3517evm_soc_init);
  162. module_exit(am3517evm_soc_exit);
  163. MODULE_AUTHOR("Anuj Aggarwal <anuj.aggarwal@ti.com>");
  164. MODULE_DESCRIPTION("ALSA SoC OMAP3517 / AM3517 EVM");
  165. MODULE_LICENSE("GPL v2");