davinci-sffsdr.c 4.3 KB

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