omap2evm.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 <plat/mcbsp.h>
  33. #include "omap-mcbsp.h"
  34. #include "omap-pcm.h"
  35. static int omap2evm_hw_params(struct snd_pcm_substream *substream,
  36. struct snd_pcm_hw_params *params)
  37. {
  38. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  39. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  40. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  41. int ret;
  42. /* Set codec DAI configuration */
  43. ret = snd_soc_dai_set_fmt(codec_dai,
  44. SND_SOC_DAIFMT_I2S |
  45. SND_SOC_DAIFMT_NB_NF |
  46. SND_SOC_DAIFMT_CBM_CFM);
  47. if (ret < 0) {
  48. printk(KERN_ERR "can't set codec DAI configuration\n");
  49. return ret;
  50. }
  51. /* Set cpu DAI configuration */
  52. ret = snd_soc_dai_set_fmt(cpu_dai,
  53. SND_SOC_DAIFMT_I2S |
  54. SND_SOC_DAIFMT_NB_NF |
  55. SND_SOC_DAIFMT_CBM_CFM);
  56. if (ret < 0) {
  57. printk(KERN_ERR "can't set cpu DAI configuration\n");
  58. return ret;
  59. }
  60. /* Set the codec system clock for DAC and ADC */
  61. ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
  62. SND_SOC_CLOCK_IN);
  63. if (ret < 0) {
  64. printk(KERN_ERR "can't set codec system clock\n");
  65. return ret;
  66. }
  67. return 0;
  68. }
  69. static struct snd_soc_ops omap2evm_ops = {
  70. .hw_params = omap2evm_hw_params,
  71. };
  72. /* Digital audio interface glue - connects codec <--> CPU */
  73. static struct snd_soc_dai_link omap2evm_dai = {
  74. .name = "TWL4030",
  75. .stream_name = "TWL4030",
  76. .cpu_dai_name = "omap-mcbsp-dai.1",
  77. .codec_dai_name = "twl4030-hifi",
  78. .platform_name = "omap-pcm-audio",
  79. .codec_name = "twl4030-codec",
  80. .ops = &omap2evm_ops,
  81. };
  82. /* Audio machine driver */
  83. static struct snd_soc_card snd_soc_omap2evm = {
  84. .name = "omap2evm",
  85. .dai_link = &omap2evm_dai,
  86. .num_links = 1,
  87. };
  88. static struct platform_device *omap2evm_snd_device;
  89. static int __init omap2evm_soc_init(void)
  90. {
  91. int ret;
  92. if (!machine_is_omap2evm())
  93. return -ENODEV;
  94. printk(KERN_INFO "omap2evm SoC init\n");
  95. omap2evm_snd_device = platform_device_alloc("soc-audio", -1);
  96. if (!omap2evm_snd_device) {
  97. printk(KERN_ERR "Platform device allocation failed\n");
  98. return -ENOMEM;
  99. }
  100. platform_set_drvdata(omap2evm_snd_device, &snd_soc_omap2evm);
  101. ret = platform_device_add(omap2evm_snd_device);
  102. if (ret)
  103. goto err1;
  104. return 0;
  105. err1:
  106. printk(KERN_ERR "Unable to add platform device\n");
  107. platform_device_put(omap2evm_snd_device);
  108. return ret;
  109. }
  110. module_init(omap2evm_soc_init);
  111. static void __exit omap2evm_soc_exit(void)
  112. {
  113. platform_device_unregister(omap2evm_snd_device);
  114. }
  115. module_exit(omap2evm_soc_exit);
  116. MODULE_AUTHOR("Arun KS <arunks@mistralsolutions.com>");
  117. MODULE_DESCRIPTION("ALSA SoC omap2evm");
  118. MODULE_LICENSE("GPL");