omap3beagle.c 3.7 KB

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