omap3evm.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 <plat/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. /* twl4030 setup */
  85. static struct twl4030_setup_data twl4030_setup = {
  86. .ramp_delay_value = 4,
  87. .sysclk = 26000,
  88. };
  89. /* Audio subsystem */
  90. static struct snd_soc_device omap3evm_snd_devdata = {
  91. .card = &snd_soc_omap3evm,
  92. .codec_dev = &soc_codec_dev_twl4030,
  93. .codec_data = &twl4030_setup,
  94. };
  95. static struct platform_device *omap3evm_snd_device;
  96. static int __init omap3evm_soc_init(void)
  97. {
  98. int ret;
  99. if (!machine_is_omap3evm()) {
  100. pr_err("Not OMAP3 EVM!\n");
  101. return -ENODEV;
  102. }
  103. pr_info("OMAP3 EVM SoC init\n");
  104. omap3evm_snd_device = platform_device_alloc("soc-audio", -1);
  105. if (!omap3evm_snd_device) {
  106. printk(KERN_ERR "Platform device allocation failed\n");
  107. return -ENOMEM;
  108. }
  109. platform_set_drvdata(omap3evm_snd_device, &omap3evm_snd_devdata);
  110. omap3evm_snd_devdata.dev = &omap3evm_snd_device->dev;
  111. *(unsigned int *)omap3evm_dai.cpu_dai->private_data = 1;
  112. ret = platform_device_add(omap3evm_snd_device);
  113. if (ret)
  114. goto err1;
  115. return 0;
  116. err1:
  117. printk(KERN_ERR "Unable to add platform device\n");
  118. platform_device_put(omap3evm_snd_device);
  119. return ret;
  120. }
  121. static void __exit omap3evm_soc_exit(void)
  122. {
  123. platform_device_unregister(omap3evm_snd_device);
  124. }
  125. module_init(omap3evm_soc_init);
  126. module_exit(omap3evm_soc_exit);
  127. MODULE_AUTHOR("Anuj Aggarwal <anuj.aggarwal@ti.com>");
  128. MODULE_DESCRIPTION("ALSA SoC OMAP3 EVM");
  129. MODULE_LICENSE("GPL v2");