overo.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * overo.c -- SoC audio for Gumstix Overo
  3. *
  4. * Author: Steve Sakoman <steve@sakoman.com>
  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 overo_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 overo_ops = {
  67. .hw_params = overo_hw_params,
  68. };
  69. /* Digital audio interface glue - connects codec <--> CPU */
  70. static struct snd_soc_dai_link overo_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 = &overo_ops,
  78. };
  79. /* Audio machine driver */
  80. static struct snd_soc_card snd_soc_card_overo = {
  81. .name = "overo",
  82. .dai_link = &overo_dai,
  83. .num_links = 1,
  84. };
  85. static struct platform_device *overo_snd_device;
  86. static int __init overo_soc_init(void)
  87. {
  88. int ret;
  89. if (!(machine_is_overo() || machine_is_cm_t35())) {
  90. pr_debug("Incomatible machine!\n");
  91. return -ENODEV;
  92. }
  93. printk(KERN_INFO "overo SoC init\n");
  94. overo_snd_device = platform_device_alloc("soc-audio", -1);
  95. if (!overo_snd_device) {
  96. printk(KERN_ERR "Platform device allocation failed\n");
  97. return -ENOMEM;
  98. }
  99. platform_set_drvdata(overo_snd_device, &snd_soc_card_overo);
  100. ret = platform_device_add(overo_snd_device);
  101. if (ret)
  102. goto err1;
  103. return 0;
  104. err1:
  105. printk(KERN_ERR "Unable to add platform device\n");
  106. platform_device_put(overo_snd_device);
  107. return ret;
  108. }
  109. module_init(overo_soc_init);
  110. static void __exit overo_soc_exit(void)
  111. {
  112. platform_device_unregister(overo_snd_device);
  113. }
  114. module_exit(overo_soc_exit);
  115. MODULE_AUTHOR("Steve Sakoman <steve@sakoman.com>");
  116. MODULE_DESCRIPTION("ALSA SoC overo");
  117. MODULE_LICENSE("GPL");