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