omap3evm.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * omap3evm.c -- ALSA SoC support for OMAP3 EVM
  3. *
  4. * Author: Anuj Aggarwal <anuj.aggarwal@ti.com>
  5. *
  6. * Based on sound/soc/omap/beagle.c by Steve Sakoman
  7. *
  8. * Copyright (C) 2008 Texas Instruments, Incorporated
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation version 2.
  13. *
  14. * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
  15. * whether express or implied; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. */
  19. #include <linux/clk.h>
  20. #include <linux/platform_device.h>
  21. #include <sound/core.h>
  22. #include <sound/pcm.h>
  23. #include <sound/soc.h>
  24. #include <sound/soc-dapm.h>
  25. #include <asm/mach-types.h>
  26. #include <mach/hardware.h>
  27. #include <mach/gpio.h>
  28. #include <mach/mcbsp.h>
  29. #include "omap-mcbsp.h"
  30. #include "omap-pcm.h"
  31. #include "../codecs/twl4030.h"
  32. static int omap3evm_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->dai->codec_dai;
  37. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  38. int ret;
  39. /* Set codec DAI configuration */
  40. ret = snd_soc_dai_set_fmt(codec_dai,
  41. SND_SOC_DAIFMT_I2S |
  42. SND_SOC_DAIFMT_NB_NF |
  43. SND_SOC_DAIFMT_CBM_CFM);
  44. if (ret < 0) {
  45. printk(KERN_ERR "Can't set codec DAI configuration\n");
  46. return ret;
  47. }
  48. /* Set cpu DAI configuration */
  49. ret = snd_soc_dai_set_fmt(cpu_dai,
  50. SND_SOC_DAIFMT_I2S |
  51. SND_SOC_DAIFMT_NB_NF |
  52. SND_SOC_DAIFMT_CBM_CFM);
  53. if (ret < 0) {
  54. printk(KERN_ERR "Can't set cpu DAI configuration\n");
  55. return ret;
  56. }
  57. /* Set the codec system clock for DAC and ADC */
  58. ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
  59. SND_SOC_CLOCK_IN);
  60. if (ret < 0) {
  61. printk(KERN_ERR "Can't set codec system clock\n");
  62. return ret;
  63. }
  64. return 0;
  65. }
  66. static struct snd_soc_ops omap3evm_ops = {
  67. .hw_params = omap3evm_hw_params,
  68. };
  69. /* Digital audio interface glue - connects codec <--> CPU */
  70. static struct snd_soc_dai_link omap3evm_dai = {
  71. .name = "TWL4030",
  72. .stream_name = "TWL4030",
  73. .cpu_dai = &omap_mcbsp_dai[0],
  74. .codec_dai = &twl4030_dai[TWL4030_DAI_HIFI],
  75. .ops = &omap3evm_ops,
  76. };
  77. /* Audio machine driver */
  78. static struct snd_soc_card snd_soc_omap3evm = {
  79. .name = "omap3evm",
  80. .platform = &omap_soc_platform,
  81. .dai_link = &omap3evm_dai,
  82. .num_links = 1,
  83. };
  84. /* Audio subsystem */
  85. static struct snd_soc_device omap3evm_snd_devdata = {
  86. .card = &snd_soc_omap3evm,
  87. .codec_dev = &soc_codec_dev_twl4030,
  88. };
  89. static struct platform_device *omap3evm_snd_device;
  90. static int __init omap3evm_soc_init(void)
  91. {
  92. int ret;
  93. if (!machine_is_omap3evm()) {
  94. pr_err("Not OMAP3 EVM!\n");
  95. return -ENODEV;
  96. }
  97. pr_info("OMAP3 EVM SoC init\n");
  98. omap3evm_snd_device = platform_device_alloc("soc-audio", -1);
  99. if (!omap3evm_snd_device) {
  100. printk(KERN_ERR "Platform device allocation failed\n");
  101. return -ENOMEM;
  102. }
  103. platform_set_drvdata(omap3evm_snd_device, &omap3evm_snd_devdata);
  104. omap3evm_snd_devdata.dev = &omap3evm_snd_device->dev;
  105. *(unsigned int *)omap3evm_dai.cpu_dai->private_data = 1;
  106. ret = platform_device_add(omap3evm_snd_device);
  107. if (ret)
  108. goto err1;
  109. return 0;
  110. err1:
  111. printk(KERN_ERR "Unable to add platform device\n");
  112. platform_device_put(omap3evm_snd_device);
  113. return ret;
  114. }
  115. static void __exit omap3evm_soc_exit(void)
  116. {
  117. platform_device_unregister(omap3evm_snd_device);
  118. }
  119. module_init(omap3evm_soc_init);
  120. module_exit(omap3evm_soc_exit);
  121. MODULE_AUTHOR("Anuj Aggarwal <anuj.aggarwal@ti.com>");
  122. MODULE_DESCRIPTION("ALSA SoC OMAP3 EVM");
  123. MODULE_LICENSE("GPL v2");