omap2evm.c 3.5 KB

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