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