overo.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 <sound/soc-dapm.h>
  27. #include <asm/mach-types.h>
  28. #include <mach/hardware.h>
  29. #include <mach/gpio.h>
  30. #include <mach/mcbsp.h>
  31. #include "omap-mcbsp.h"
  32. #include "omap-pcm.h"
  33. #include "../codecs/twl4030.h"
  34. static int overo_hw_params(struct snd_pcm_substream *substream,
  35. struct snd_pcm_hw_params *params)
  36. {
  37. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  38. struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
  39. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  40. int ret;
  41. /* Set codec DAI configuration */
  42. ret = snd_soc_dai_set_fmt(codec_dai,
  43. SND_SOC_DAIFMT_I2S |
  44. SND_SOC_DAIFMT_NB_NF |
  45. SND_SOC_DAIFMT_CBM_CFM);
  46. if (ret < 0) {
  47. printk(KERN_ERR "can't set codec DAI configuration\n");
  48. return ret;
  49. }
  50. /* Set cpu DAI configuration */
  51. ret = snd_soc_dai_set_fmt(cpu_dai,
  52. SND_SOC_DAIFMT_I2S |
  53. SND_SOC_DAIFMT_NB_NF |
  54. SND_SOC_DAIFMT_CBM_CFM);
  55. if (ret < 0) {
  56. printk(KERN_ERR "can't set cpu DAI configuration\n");
  57. return ret;
  58. }
  59. /* Set the codec system clock for DAC and ADC */
  60. ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
  61. SND_SOC_CLOCK_IN);
  62. if (ret < 0) {
  63. printk(KERN_ERR "can't set codec system clock\n");
  64. return ret;
  65. }
  66. return 0;
  67. }
  68. static struct snd_soc_ops overo_ops = {
  69. .hw_params = overo_hw_params,
  70. };
  71. /* Digital audio interface glue - connects codec <--> CPU */
  72. static struct snd_soc_dai_link overo_dai = {
  73. .name = "TWL4030",
  74. .stream_name = "TWL4030",
  75. .cpu_dai = &omap_mcbsp_dai[0],
  76. .codec_dai = &twl4030_dai[TWL4030_DAI_HIFI],
  77. .ops = &overo_ops,
  78. };
  79. /* Audio machine driver */
  80. static struct snd_soc_card snd_soc_card_overo = {
  81. .name = "overo",
  82. .platform = &omap_soc_platform,
  83. .dai_link = &overo_dai,
  84. .num_links = 1,
  85. };
  86. /* Audio subsystem */
  87. static struct snd_soc_device overo_snd_devdata = {
  88. .card = &snd_soc_card_overo,
  89. .codec_dev = &soc_codec_dev_twl4030,
  90. };
  91. static struct platform_device *overo_snd_device;
  92. static int __init overo_soc_init(void)
  93. {
  94. int ret;
  95. if (!machine_is_overo()) {
  96. pr_debug("Not Overo!\n");
  97. return -ENODEV;
  98. }
  99. printk(KERN_INFO "overo SoC init\n");
  100. overo_snd_device = platform_device_alloc("soc-audio", -1);
  101. if (!overo_snd_device) {
  102. printk(KERN_ERR "Platform device allocation failed\n");
  103. return -ENOMEM;
  104. }
  105. platform_set_drvdata(overo_snd_device, &overo_snd_devdata);
  106. overo_snd_devdata.dev = &overo_snd_device->dev;
  107. *(unsigned int *)overo_dai.cpu_dai->private_data = 1; /* McBSP2 */
  108. ret = platform_device_add(overo_snd_device);
  109. if (ret)
  110. goto err1;
  111. return 0;
  112. err1:
  113. printk(KERN_ERR "Unable to add platform device\n");
  114. platform_device_put(overo_snd_device);
  115. return ret;
  116. }
  117. module_init(overo_soc_init);
  118. static void __exit overo_soc_exit(void)
  119. {
  120. platform_device_unregister(overo_snd_device);
  121. }
  122. module_exit(overo_soc_exit);
  123. MODULE_AUTHOR("Steve Sakoman <steve@sakoman.com>");
  124. MODULE_DESCRIPTION("ALSA SoC overo");
  125. MODULE_LICENSE("GPL");