omap3beagle.c 4.0 KB

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