omap2evm.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * omap2evm.c -- SoC audio machine driver for omap2evm board
  3. *
  4. * Author: Arun KS <arunks@mistralsolutions.com>
  5. *
  6. * Based on sound/soc/omap/overo.c by Steve Sakoman
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. *
  22. */
  23. #include <linux/clk.h>
  24. #include <linux/platform_device.h>
  25. #include <sound/core.h>
  26. #include <sound/pcm.h>
  27. #include <sound/soc.h>
  28. #include <sound/soc-dapm.h>
  29. #include <asm/mach-types.h>
  30. #include <mach/hardware.h>
  31. #include <mach/gpio.h>
  32. #include <mach/mcbsp.h>
  33. #include "omap-mcbsp.h"
  34. #include "omap-pcm.h"
  35. #include "../codecs/twl4030.h"
  36. static int omap2evm_hw_params(struct snd_pcm_substream *substream,
  37. struct snd_pcm_hw_params *params,
  38. struct snd_soc_dai *dai)
  39. {
  40. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  41. struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
  42. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  43. int ret;
  44. /* Set codec DAI configuration */
  45. ret = snd_soc_dai_set_fmt(codec_dai,
  46. SND_SOC_DAIFMT_I2S |
  47. SND_SOC_DAIFMT_NB_NF |
  48. SND_SOC_DAIFMT_CBM_CFM);
  49. if (ret < 0) {
  50. printk(KERN_ERR "can't set codec DAI configuration\n");
  51. return ret;
  52. }
  53. /* Set cpu DAI configuration */
  54. ret = snd_soc_dai_set_fmt(cpu_dai,
  55. SND_SOC_DAIFMT_I2S |
  56. SND_SOC_DAIFMT_NB_NF |
  57. SND_SOC_DAIFMT_CBM_CFM);
  58. if (ret < 0) {
  59. printk(KERN_ERR "can't set cpu DAI configuration\n");
  60. return ret;
  61. }
  62. /* Set the codec system clock for DAC and ADC */
  63. ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
  64. SND_SOC_CLOCK_IN);
  65. if (ret < 0) {
  66. printk(KERN_ERR "can't set codec system clock\n");
  67. return ret;
  68. }
  69. return 0;
  70. }
  71. static struct snd_soc_ops omap2evm_ops = {
  72. .hw_params = omap2evm_hw_params,
  73. };
  74. /* Digital audio interface glue - connects codec <--> CPU */
  75. static struct snd_soc_dai_link omap2evm_dai = {
  76. .name = "TWL4030",
  77. .stream_name = "TWL4030",
  78. .cpu_dai = &omap_mcbsp_dai[0],
  79. .codec_dai = &twl4030_dai[TWL4030_DAI_HIFI],
  80. .ops = &omap2evm_ops,
  81. };
  82. /* Audio machine driver */
  83. static struct snd_soc_card snd_soc_omap2evm = {
  84. .name = "omap2evm",
  85. .platform = &omap_soc_platform,
  86. .dai_link = &omap2evm_dai,
  87. .num_links = 1,
  88. };
  89. /* Audio subsystem */
  90. static struct snd_soc_device omap2evm_snd_devdata = {
  91. .card = &snd_soc_omap2evm,
  92. .codec_dev = &soc_codec_dev_twl4030,
  93. };
  94. static struct platform_device *omap2evm_snd_device;
  95. static int __init omap2evm_soc_init(void)
  96. {
  97. int ret;
  98. if (!machine_is_omap2evm()) {
  99. pr_debug("Not omap2evm!\n");
  100. return -ENODEV;
  101. }
  102. printk(KERN_INFO "omap2evm SoC init\n");
  103. omap2evm_snd_device = platform_device_alloc("soc-audio", -1);
  104. if (!omap2evm_snd_device) {
  105. printk(KERN_ERR "Platform device allocation failed\n");
  106. return -ENOMEM;
  107. }
  108. platform_set_drvdata(omap2evm_snd_device, &omap2evm_snd_devdata);
  109. omap2evm_snd_devdata.dev = &omap2evm_snd_device->dev;
  110. *(unsigned int *)omap2evm_dai.cpu_dai->private_data = 1; /* McBSP2 */
  111. ret = platform_device_add(omap2evm_snd_device);
  112. if (ret)
  113. goto err1;
  114. return 0;
  115. err1:
  116. printk(KERN_ERR "Unable to add platform device\n");
  117. platform_device_put(omap2evm_snd_device);
  118. return ret;
  119. }
  120. module_init(omap2evm_soc_init);
  121. static void __exit omap2evm_soc_exit(void)
  122. {
  123. platform_device_unregister(omap2evm_snd_device);
  124. }
  125. module_exit(omap2evm_soc_exit);
  126. MODULE_AUTHOR("Arun KS <arunks@mistralsolutions.com>");
  127. MODULE_DESCRIPTION("ALSA SoC omap2evm");
  128. MODULE_LICENSE("GPL");