omap3evm.c 3.4 KB

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