igep0020.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * igep0020.c -- SoC audio for IGEP v2
  3. *
  4. * Based on sound/soc/omap/overo.c by Steve Sakoman
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  18. * 02110-1301 USA
  19. *
  20. */
  21. #include <linux/clk.h>
  22. #include <linux/platform_device.h>
  23. #include <sound/core.h>
  24. #include <sound/pcm.h>
  25. #include <sound/soc.h>
  26. #include <asm/mach-types.h>
  27. #include <mach/hardware.h>
  28. #include <mach/gpio.h>
  29. #include <plat/mcbsp.h>
  30. #include "omap-mcbsp.h"
  31. #include "omap-pcm.h"
  32. static int igep2_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->codec_dai;
  37. struct snd_soc_dai *cpu_dai = rtd->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 igep2_ops = {
  67. .hw_params = igep2_hw_params,
  68. };
  69. /* Digital audio interface glue - connects codec <--> CPU */
  70. static struct snd_soc_dai_link igep2_dai = {
  71. .name = "TWL4030",
  72. .stream_name = "TWL4030",
  73. .cpu_dai_name = "omap-mcbsp-dai.1",
  74. .codec_dai_name = "twl4030-hifi",
  75. .platform_name = "omap-pcm-audio",
  76. .codec_name = "twl4030-codec",
  77. .ops = &igep2_ops,
  78. };
  79. /* Audio machine driver */
  80. static struct snd_soc_card snd_soc_card_igep2 = {
  81. .name = "igep2",
  82. .dai_link = &igep2_dai,
  83. .num_links = 1,
  84. };
  85. static struct platform_device *igep2_snd_device;
  86. static int __init igep2_soc_init(void)
  87. {
  88. int ret;
  89. if (!machine_is_igep0020())
  90. return -ENODEV;
  91. printk(KERN_INFO "IGEP v2 SoC init\n");
  92. igep2_snd_device = platform_device_alloc("soc-audio", -1);
  93. if (!igep2_snd_device) {
  94. printk(KERN_ERR "Platform device allocation failed\n");
  95. return -ENOMEM;
  96. }
  97. platform_set_drvdata(igep2_snd_device, &snd_soc_card_igep2);
  98. ret = platform_device_add(igep2_snd_device);
  99. if (ret)
  100. goto err1;
  101. return 0;
  102. err1:
  103. printk(KERN_ERR "Unable to add platform device\n");
  104. platform_device_put(igep2_snd_device);
  105. return ret;
  106. }
  107. module_init(igep2_soc_init);
  108. static void __exit igep2_soc_exit(void)
  109. {
  110. platform_device_unregister(igep2_snd_device);
  111. }
  112. module_exit(igep2_soc_exit);
  113. MODULE_AUTHOR("Enric Balletbo i Serra <eballetbo@iseebcn.com>");
  114. MODULE_DESCRIPTION("ALSA SoC IGEP v2");
  115. MODULE_LICENSE("GPL");