davinci-sffsdr.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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/plat-sffsdr/sffsdr-fpga.h>
  26. #include <mach/mcbsp.h>
  27. #include <mach/edma.h>
  28. #include "../codecs/pcm3008.h"
  29. #include "davinci-pcm.h"
  30. #include "davinci-i2s.h"
  31. static int sffsdr_hw_params(struct snd_pcm_substream *substream,
  32. struct snd_pcm_hw_params *params)
  33. {
  34. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  35. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  36. int fs;
  37. int ret = 0;
  38. /* Set cpu DAI configuration:
  39. * CLKX and CLKR are the inputs for the Sample Rate Generator.
  40. * FSX and FSR are outputs, driven by the sample Rate Generator. */
  41. ret = snd_soc_dai_set_fmt(cpu_dai,
  42. SND_SOC_DAIFMT_RIGHT_J |
  43. SND_SOC_DAIFMT_CBM_CFS |
  44. SND_SOC_DAIFMT_IB_NF);
  45. if (ret < 0)
  46. return ret;
  47. /* Fsref can be 32000, 44100 or 48000. */
  48. fs = params_rate(params);
  49. pr_debug("sffsdr_hw_params: rate = %d Hz\n", fs);
  50. return sffsdr_fpga_set_codec_fs(fs);
  51. }
  52. static struct snd_soc_ops sffsdr_ops = {
  53. .hw_params = sffsdr_hw_params,
  54. };
  55. /* davinci-sffsdr digital audio interface glue - connects codec <--> CPU */
  56. static struct snd_soc_dai_link sffsdr_dai = {
  57. .name = "PCM3008", /* Codec name */
  58. .stream_name = "PCM3008 HiFi",
  59. .cpu_dai = &davinci_i2s_dai,
  60. .codec_dai = &pcm3008_dai,
  61. .ops = &sffsdr_ops,
  62. };
  63. /* davinci-sffsdr audio machine driver */
  64. static struct snd_soc_machine snd_soc_machine_sffsdr = {
  65. .name = "DaVinci SFFSDR",
  66. .dai_link = &sffsdr_dai,
  67. .num_links = 1,
  68. };
  69. /* sffsdr audio private data */
  70. static struct pcm3008_setup_data sffsdr_pcm3008_setup = {
  71. .dem0_pin = GPIO(45),
  72. .dem1_pin = GPIO(46),
  73. .pdad_pin = GPIO(47),
  74. .pdda_pin = GPIO(38),
  75. };
  76. /* sffsdr audio subsystem */
  77. static struct snd_soc_device sffsdr_snd_devdata = {
  78. .machine = &snd_soc_machine_sffsdr,
  79. .platform = &davinci_soc_platform,
  80. .codec_dev = &soc_codec_dev_pcm3008,
  81. .codec_data = &sffsdr_pcm3008_setup,
  82. };
  83. static struct resource sffsdr_snd_resources[] = {
  84. {
  85. .start = DAVINCI_MCBSP_BASE,
  86. .end = DAVINCI_MCBSP_BASE + SZ_8K - 1,
  87. .flags = IORESOURCE_MEM,
  88. },
  89. };
  90. static struct evm_snd_platform_data sffsdr_snd_data = {
  91. .tx_dma_ch = DAVINCI_DMA_MCBSP_TX,
  92. .rx_dma_ch = DAVINCI_DMA_MCBSP_RX,
  93. };
  94. static struct platform_device *sffsdr_snd_device;
  95. static int __init sffsdr_init(void)
  96. {
  97. int ret;
  98. sffsdr_snd_device = platform_device_alloc("soc-audio", 0);
  99. if (!sffsdr_snd_device) {
  100. printk(KERN_ERR "platform device allocation failed\n");
  101. return -ENOMEM;
  102. }
  103. platform_set_drvdata(sffsdr_snd_device, &sffsdr_snd_devdata);
  104. sffsdr_snd_devdata.dev = &sffsdr_snd_device->dev;
  105. sffsdr_snd_device->dev.platform_data = &sffsdr_snd_data;
  106. ret = platform_device_add_resources(sffsdr_snd_device,
  107. sffsdr_snd_resources,
  108. ARRAY_SIZE(sffsdr_snd_resources));
  109. if (ret) {
  110. printk(KERN_ERR "platform device add ressources failed\n");
  111. goto error;
  112. }
  113. ret = platform_device_add(sffsdr_snd_device);
  114. if (ret)
  115. goto error;
  116. return ret;
  117. error:
  118. platform_device_put(sffsdr_snd_device);
  119. return ret;
  120. }
  121. static void __exit sffsdr_exit(void)
  122. {
  123. platform_device_unregister(sffsdr_snd_device);
  124. }
  125. module_init(sffsdr_init);
  126. module_exit(sffsdr_exit);
  127. MODULE_AUTHOR("Hugo Villeneuve");
  128. MODULE_DESCRIPTION("Lyrtech SFFSDR ASoC driver");
  129. MODULE_LICENSE("GPL");