davinci-sffsdr.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 <asm/dma.h>
  24. #include <asm/mach-types.h>
  25. #ifdef CONFIG_SFFSDR_FPGA
  26. #include <asm/plat-sffsdr/sffsdr-fpga.h>
  27. #endif
  28. #include <mach/edma.h>
  29. #include "../codecs/pcm3008.h"
  30. #include "davinci-pcm.h"
  31. #include "davinci-i2s.h"
  32. /*
  33. * CLKX and CLKR are the inputs for the Sample Rate Generator.
  34. * FSX and FSR are outputs, driven by the sample Rate Generator.
  35. */
  36. #define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
  37. SND_SOC_DAIFMT_CBM_CFS | \
  38. SND_SOC_DAIFMT_IB_NF)
  39. static int sffsdr_hw_params(struct snd_pcm_substream *substream,
  40. struct snd_pcm_hw_params *params)
  41. {
  42. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  43. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  44. int fs;
  45. int ret = 0;
  46. /* Fsref can be 32000, 44100 or 48000. */
  47. fs = params_rate(params);
  48. #ifndef CONFIG_SFFSDR_FPGA
  49. /* Without the FPGA module, the Fs is fixed at 44100 Hz */
  50. if (fs != 44100) {
  51. pr_debug("warning: only 44.1 kHz is supported without SFFSDR FPGA module\n");
  52. return -EINVAL;
  53. }
  54. #endif
  55. /* set cpu DAI configuration */
  56. ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
  57. if (ret < 0)
  58. return ret;
  59. pr_debug("sffsdr_hw_params: rate = %d Hz\n", fs);
  60. #ifndef CONFIG_SFFSDR_FPGA
  61. return 0;
  62. #else
  63. return sffsdr_fpga_set_codec_fs(fs);
  64. #endif
  65. }
  66. static struct snd_soc_ops sffsdr_ops = {
  67. .hw_params = sffsdr_hw_params,
  68. };
  69. /* davinci-sffsdr digital audio interface glue - connects codec <--> CPU */
  70. static struct snd_soc_dai_link sffsdr_dai = {
  71. .name = "PCM3008", /* Codec name */
  72. .stream_name = "PCM3008 HiFi",
  73. .cpu_dai_name = "davinci-mcbsp",
  74. .codec_dai_name = "pcm3008-hifi",
  75. .codec_name = "pcm3008-codec",
  76. .platform_name = "davinci-pcm-audio",
  77. .ops = &sffsdr_ops,
  78. };
  79. /* davinci-sffsdr audio machine driver */
  80. static struct snd_soc_card snd_soc_sffsdr = {
  81. .name = "DaVinci SFFSDR",
  82. .owner = THIS_MODULE,
  83. .dai_link = &sffsdr_dai,
  84. .num_links = 1,
  85. };
  86. /* sffsdr audio private data */
  87. static struct pcm3008_setup_data sffsdr_pcm3008_setup = {
  88. .dem0_pin = GPIO(45),
  89. .dem1_pin = GPIO(46),
  90. .pdad_pin = GPIO(47),
  91. .pdda_pin = GPIO(38),
  92. };
  93. struct platform_device pcm3008_codec = {
  94. .name = "pcm3008-codec",
  95. .id = 0,
  96. .dev = {
  97. .platform_data = &sffsdr_pcm3008_setup,
  98. },
  99. };
  100. static struct resource sffsdr_snd_resources[] = {
  101. {
  102. .start = DAVINCI_MCBSP_BASE,
  103. .end = DAVINCI_MCBSP_BASE + SZ_8K - 1,
  104. .flags = IORESOURCE_MEM,
  105. },
  106. };
  107. static struct evm_snd_platform_data sffsdr_snd_data = {
  108. .tx_dma_ch = DAVINCI_DMA_MCBSP_TX,
  109. .rx_dma_ch = DAVINCI_DMA_MCBSP_RX,
  110. };
  111. static struct platform_device *sffsdr_snd_device;
  112. static int __init sffsdr_init(void)
  113. {
  114. int ret;
  115. if (!machine_is_sffsdr())
  116. return -EINVAL;
  117. platform_device_register(&pcm3008_codec);
  118. sffsdr_snd_device = platform_device_alloc("soc-audio", 0);
  119. if (!sffsdr_snd_device) {
  120. printk(KERN_ERR "platform device allocation failed\n");
  121. return -ENOMEM;
  122. }
  123. platform_set_drvdata(sffsdr_snd_device, &snd_soc_sffsdr);
  124. platform_device_add_data(sffsdr_snd_device, &sffsdr_snd_data,
  125. sizeof(sffsdr_snd_data));
  126. ret = platform_device_add_resources(sffsdr_snd_device,
  127. sffsdr_snd_resources,
  128. ARRAY_SIZE(sffsdr_snd_resources));
  129. if (ret) {
  130. printk(KERN_ERR "platform device add resources failed\n");
  131. goto error;
  132. }
  133. ret = platform_device_add(sffsdr_snd_device);
  134. if (ret)
  135. goto error;
  136. return ret;
  137. error:
  138. platform_device_put(sffsdr_snd_device);
  139. return ret;
  140. }
  141. static void __exit sffsdr_exit(void)
  142. {
  143. platform_device_unregister(sffsdr_snd_device);
  144. platform_device_unregister(&pcm3008_codec);
  145. }
  146. module_init(sffsdr_init);
  147. module_exit(sffsdr_exit);
  148. MODULE_AUTHOR("Hugo Villeneuve");
  149. MODULE_DESCRIPTION("Lyrtech SFFSDR ASoC driver");
  150. MODULE_LICENSE("GPL");