davinci-sffsdr.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * ASoC driver for Lyrtech SFFSDR board.
  3. *
  4. * Author: Hugo Villeneuve
  5. * Copyright (C) 2008 Lyrtech inc
  6. *
  7. * Based on ASoC driver for TI DAVINCI EVM platform, original copyright follow:
  8. * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/module.h>
  15. #include <linux/moduleparam.h>
  16. #include <linux/timer.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/gpio.h>
  20. #include <sound/core.h>
  21. #include <sound/pcm.h>
  22. #include <sound/soc.h>
  23. #include <sound/soc-dapm.h>
  24. #include <asm/dma.h>
  25. #include <asm/mach-types.h>
  26. #include <asm/plat-sffsdr/sffsdr-fpga.h>
  27. #include <mach/mcbsp.h>
  28. #include <mach/edma.h>
  29. #include "../codecs/pcm3008.h"
  30. #include "davinci-pcm.h"
  31. #include "davinci-i2s.h"
  32. static int sffsdr_hw_params(struct snd_pcm_substream *substream,
  33. struct snd_pcm_hw_params *params,
  34. struct snd_soc_dai *dai)
  35. {
  36. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  37. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  38. int fs;
  39. int ret = 0;
  40. /* Set cpu DAI configuration:
  41. * CLKX and CLKR are the inputs for the Sample Rate Generator.
  42. * FSX and FSR are outputs, driven by the sample Rate Generator. */
  43. ret = snd_soc_dai_set_fmt(cpu_dai,
  44. SND_SOC_DAIFMT_RIGHT_J |
  45. SND_SOC_DAIFMT_CBM_CFS |
  46. SND_SOC_DAIFMT_IB_NF);
  47. if (ret < 0)
  48. return ret;
  49. /* Fsref can be 32000, 44100 or 48000. */
  50. fs = params_rate(params);
  51. pr_debug("sffsdr_hw_params: rate = %d Hz\n", fs);
  52. return sffsdr_fpga_set_codec_fs(fs);
  53. }
  54. static struct snd_soc_ops sffsdr_ops = {
  55. .hw_params = sffsdr_hw_params,
  56. };
  57. /* davinci-sffsdr digital audio interface glue - connects codec <--> CPU */
  58. static struct snd_soc_dai_link sffsdr_dai = {
  59. .name = "PCM3008", /* Codec name */
  60. .stream_name = "PCM3008 HiFi",
  61. .cpu_dai = &davinci_i2s_dai,
  62. .codec_dai = &pcm3008_dai,
  63. .ops = &sffsdr_ops,
  64. };
  65. /* davinci-sffsdr audio machine driver */
  66. static struct snd_soc_card snd_soc_sffsdr = {
  67. .name = "DaVinci SFFSDR",
  68. .platform = &davinci_soc_platform,
  69. .dai_link = &sffsdr_dai,
  70. .num_links = 1,
  71. };
  72. /* sffsdr audio private data */
  73. static struct pcm3008_setup_data sffsdr_pcm3008_setup = {
  74. .dem0_pin = GPIO(45),
  75. .dem1_pin = GPIO(46),
  76. .pdad_pin = GPIO(47),
  77. .pdda_pin = GPIO(38),
  78. };
  79. /* sffsdr audio subsystem */
  80. static struct snd_soc_device sffsdr_snd_devdata = {
  81. .card = &snd_soc_sffsdr,
  82. .codec_dev = &soc_codec_dev_pcm3008,
  83. .codec_data = &sffsdr_pcm3008_setup,
  84. };
  85. static struct resource sffsdr_snd_resources[] = {
  86. {
  87. .start = DAVINCI_MCBSP_BASE,
  88. .end = DAVINCI_MCBSP_BASE + SZ_8K - 1,
  89. .flags = IORESOURCE_MEM,
  90. },
  91. };
  92. static struct evm_snd_platform_data sffsdr_snd_data = {
  93. .tx_dma_ch = DAVINCI_DMA_MCBSP_TX,
  94. .rx_dma_ch = DAVINCI_DMA_MCBSP_RX,
  95. };
  96. static struct platform_device *sffsdr_snd_device;
  97. static int __init sffsdr_init(void)
  98. {
  99. int ret;
  100. if (!machine_is_sffsdr())
  101. return -EINVAL;
  102. sffsdr_snd_device = platform_device_alloc("soc-audio", 0);
  103. if (!sffsdr_snd_device) {
  104. printk(KERN_ERR "platform device allocation failed\n");
  105. return -ENOMEM;
  106. }
  107. platform_set_drvdata(sffsdr_snd_device, &sffsdr_snd_devdata);
  108. sffsdr_snd_devdata.dev = &sffsdr_snd_device->dev;
  109. sffsdr_snd_device->dev.platform_data = &sffsdr_snd_data;
  110. ret = platform_device_add_resources(sffsdr_snd_device,
  111. sffsdr_snd_resources,
  112. ARRAY_SIZE(sffsdr_snd_resources));
  113. if (ret) {
  114. printk(KERN_ERR "platform device add ressources failed\n");
  115. goto error;
  116. }
  117. ret = platform_device_add(sffsdr_snd_device);
  118. if (ret)
  119. goto error;
  120. return ret;
  121. error:
  122. platform_device_put(sffsdr_snd_device);
  123. return ret;
  124. }
  125. static void __exit sffsdr_exit(void)
  126. {
  127. platform_device_unregister(sffsdr_snd_device);
  128. }
  129. module_init(sffsdr_init);
  130. module_exit(sffsdr_exit);
  131. MODULE_AUTHOR("Hugo Villeneuve");
  132. MODULE_DESCRIPTION("Lyrtech SFFSDR ASoC driver");
  133. MODULE_LICENSE("GPL");