omap3beagle.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 <asm/mach-types.h>
  27. #include <mach/hardware.h>
  28. #include <mach/gpio.h>
  29. #include <plat/mcbsp.h>
  30. #include "omap-mcbsp.h"
  31. #include "omap-pcm.h"
  32. static int omap3beagle_hw_params(struct snd_pcm_substream *substream,
  33. struct snd_pcm_hw_params *params)
  34. {
  35. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  36. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  37. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  38. unsigned int fmt;
  39. int ret;
  40. switch (params_channels(params)) {
  41. case 2: /* Stereo I2S mode */
  42. fmt = SND_SOC_DAIFMT_I2S |
  43. SND_SOC_DAIFMT_NB_NF |
  44. SND_SOC_DAIFMT_CBM_CFM;
  45. break;
  46. case 4: /* Four channel TDM mode */
  47. fmt = SND_SOC_DAIFMT_DSP_A |
  48. SND_SOC_DAIFMT_IB_NF |
  49. SND_SOC_DAIFMT_CBM_CFM;
  50. break;
  51. default:
  52. return -EINVAL;
  53. }
  54. /* Set codec DAI configuration */
  55. ret = snd_soc_dai_set_fmt(codec_dai, fmt);
  56. if (ret < 0) {
  57. printk(KERN_ERR "can't set codec DAI configuration\n");
  58. return ret;
  59. }
  60. /* Set cpu DAI configuration */
  61. ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
  62. if (ret < 0) {
  63. printk(KERN_ERR "can't set cpu DAI configuration\n");
  64. return ret;
  65. }
  66. /* Set the codec system clock for DAC and ADC */
  67. ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
  68. SND_SOC_CLOCK_IN);
  69. if (ret < 0) {
  70. printk(KERN_ERR "can't set codec system clock\n");
  71. return ret;
  72. }
  73. return 0;
  74. }
  75. static struct snd_soc_ops omap3beagle_ops = {
  76. .hw_params = omap3beagle_hw_params,
  77. };
  78. /* Digital audio interface glue - connects codec <--> CPU */
  79. static struct snd_soc_dai_link omap3beagle_dai = {
  80. .name = "TWL4030",
  81. .stream_name = "TWL4030",
  82. .cpu_dai_name = "omap-mcbsp-dai.1",
  83. .platform_name = "omap-pcm-audio",
  84. .codec_dai_name = "twl4030-hifi",
  85. .codec_name = "twl4030-codec",
  86. .ops = &omap3beagle_ops,
  87. };
  88. /* Audio machine driver */
  89. static struct snd_soc_card snd_soc_omap3beagle = {
  90. .name = "omap3beagle",
  91. .owner = THIS_MODULE,
  92. .dai_link = &omap3beagle_dai,
  93. .num_links = 1,
  94. };
  95. static struct platform_device *omap3beagle_snd_device;
  96. static int __init omap3beagle_soc_init(void)
  97. {
  98. int ret;
  99. if (!(machine_is_omap3_beagle() || machine_is_devkit8000()))
  100. return -ENODEV;
  101. pr_info("OMAP3 Beagle/Devkit8000 SoC init\n");
  102. omap3beagle_snd_device = platform_device_alloc("soc-audio", -1);
  103. if (!omap3beagle_snd_device) {
  104. printk(KERN_ERR "Platform device allocation failed\n");
  105. return -ENOMEM;
  106. }
  107. platform_set_drvdata(omap3beagle_snd_device, &snd_soc_omap3beagle);
  108. ret = platform_device_add(omap3beagle_snd_device);
  109. if (ret)
  110. goto err1;
  111. return 0;
  112. err1:
  113. printk(KERN_ERR "Unable to add platform device\n");
  114. platform_device_put(omap3beagle_snd_device);
  115. return ret;
  116. }
  117. static void __exit omap3beagle_soc_exit(void)
  118. {
  119. platform_device_unregister(omap3beagle_snd_device);
  120. }
  121. module_init(omap3beagle_soc_init);
  122. module_exit(omap3beagle_soc_exit);
  123. MODULE_AUTHOR("Steve Sakoman <steve@sakoman.com>");
  124. MODULE_DESCRIPTION("ALSA SoC OMAP3 Beagle");
  125. MODULE_LICENSE("GPL");