s3c2412-i2s.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /* sound/soc/samsung/s3c2412-i2s.c
  2. *
  3. * ALSA Soc Audio Layer - S3C2412 I2S driver
  4. *
  5. * Copyright (c) 2006 Wolfson Microelectronics PLC.
  6. * Graeme Gregory graeme.gregory@wolfsonmicro.com
  7. * linux@wolfsonmicro.com
  8. *
  9. * Copyright (c) 2007, 2004-2005 Simtec Electronics
  10. * http://armlinux.simtec.co.uk/
  11. * Ben Dooks <ben@simtec.co.uk>
  12. *
  13. * This program is free software; you can redistribute it and/or modify it
  14. * under the terms of the GNU General Public License as published by the
  15. * Free Software Foundation; either version 2 of the License, or (at your
  16. * option) any later version.
  17. */
  18. #include <linux/delay.h>
  19. #include <linux/gpio.h>
  20. #include <linux/clk.h>
  21. #include <linux/io.h>
  22. #include <linux/module.h>
  23. #include <sound/soc.h>
  24. #include <sound/pcm_params.h>
  25. #include <mach/dma.h>
  26. #include "dma.h"
  27. #include "regs-i2s-v2.h"
  28. #include "s3c2412-i2s.h"
  29. static struct s3c2410_dma_client s3c2412_dma_client_out = {
  30. .name = "I2S PCM Stereo out"
  31. };
  32. static struct s3c2410_dma_client s3c2412_dma_client_in = {
  33. .name = "I2S PCM Stereo in"
  34. };
  35. static struct s3c_dma_params s3c2412_i2s_pcm_stereo_out = {
  36. .client = &s3c2412_dma_client_out,
  37. .channel = DMACH_I2S_OUT,
  38. .dma_addr = S3C2410_PA_IIS + S3C2412_IISTXD,
  39. .dma_size = 4,
  40. };
  41. static struct s3c_dma_params s3c2412_i2s_pcm_stereo_in = {
  42. .client = &s3c2412_dma_client_in,
  43. .channel = DMACH_I2S_IN,
  44. .dma_addr = S3C2410_PA_IIS + S3C2412_IISRXD,
  45. .dma_size = 4,
  46. };
  47. static struct s3c_i2sv2_info s3c2412_i2s;
  48. static int s3c2412_i2s_probe(struct snd_soc_dai *dai)
  49. {
  50. int ret;
  51. pr_debug("Entered %s\n", __func__);
  52. ret = s3c_i2sv2_probe(dai, &s3c2412_i2s, S3C2410_PA_IIS);
  53. if (ret)
  54. return ret;
  55. s3c2412_i2s.dma_capture = &s3c2412_i2s_pcm_stereo_in;
  56. s3c2412_i2s.dma_playback = &s3c2412_i2s_pcm_stereo_out;
  57. s3c2412_i2s.iis_cclk = clk_get(dai->dev, "i2sclk");
  58. if (IS_ERR(s3c2412_i2s.iis_cclk)) {
  59. pr_err("failed to get i2sclk clock\n");
  60. iounmap(s3c2412_i2s.regs);
  61. return PTR_ERR(s3c2412_i2s.iis_cclk);
  62. }
  63. /* Set MPLL as the source for IIS CLK */
  64. clk_set_parent(s3c2412_i2s.iis_cclk, clk_get(NULL, "mpll"));
  65. clk_enable(s3c2412_i2s.iis_cclk);
  66. s3c2412_i2s.iis_cclk = s3c2412_i2s.iis_pclk;
  67. /* Configure the I2S pins (GPE0...GPE4) in correct mode */
  68. s3c_gpio_cfgall_range(S3C2410_GPE(0), 5, S3C_GPIO_SFN(2),
  69. S3C_GPIO_PULL_NONE);
  70. return 0;
  71. }
  72. static int s3c2412_i2s_remove(struct snd_soc_dai *dai)
  73. {
  74. clk_disable(s3c2412_i2s.iis_cclk);
  75. clk_put(s3c2412_i2s.iis_cclk);
  76. iounmap(s3c2412_i2s.regs);
  77. return 0;
  78. }
  79. static int s3c2412_i2s_hw_params(struct snd_pcm_substream *substream,
  80. struct snd_pcm_hw_params *params,
  81. struct snd_soc_dai *cpu_dai)
  82. {
  83. struct s3c_i2sv2_info *i2s = snd_soc_dai_get_drvdata(cpu_dai);
  84. struct s3c_dma_params *dma_data;
  85. u32 iismod;
  86. pr_debug("Entered %s\n", __func__);
  87. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  88. dma_data = i2s->dma_playback;
  89. else
  90. dma_data = i2s->dma_capture;
  91. snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
  92. iismod = readl(i2s->regs + S3C2412_IISMOD);
  93. pr_debug("%s: r: IISMOD: %x\n", __func__, iismod);
  94. switch (params_format(params)) {
  95. case SNDRV_PCM_FORMAT_S8:
  96. iismod |= S3C2412_IISMOD_8BIT;
  97. break;
  98. case SNDRV_PCM_FORMAT_S16_LE:
  99. iismod &= ~S3C2412_IISMOD_8BIT;
  100. break;
  101. }
  102. writel(iismod, i2s->regs + S3C2412_IISMOD);
  103. pr_debug("%s: w: IISMOD: %x\n", __func__, iismod);
  104. return 0;
  105. }
  106. #define S3C2412_I2S_RATES \
  107. (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
  108. SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
  109. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
  110. static const struct snd_soc_dai_ops s3c2412_i2s_dai_ops = {
  111. .hw_params = s3c2412_i2s_hw_params,
  112. };
  113. static struct snd_soc_dai_driver s3c2412_i2s_dai = {
  114. .probe = s3c2412_i2s_probe,
  115. .remove = s3c2412_i2s_remove,
  116. .playback = {
  117. .channels_min = 2,
  118. .channels_max = 2,
  119. .rates = S3C2412_I2S_RATES,
  120. .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,
  121. },
  122. .capture = {
  123. .channels_min = 2,
  124. .channels_max = 2,
  125. .rates = S3C2412_I2S_RATES,
  126. .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,
  127. },
  128. .ops = &s3c2412_i2s_dai_ops,
  129. };
  130. static int s3c2412_iis_dev_probe(struct platform_device *pdev)
  131. {
  132. int ret = 0;
  133. ret = s3c_i2sv2_register_dai(&pdev->dev, -1, &s3c2412_i2s_dai);
  134. if (ret) {
  135. pr_err("failed to register the dai\n");
  136. return ret;
  137. }
  138. ret = asoc_dma_platform_register(&pdev->dev);
  139. if (ret) {
  140. pr_err("failed to register the DMA: %d\n", ret);
  141. goto err;
  142. }
  143. return 0;
  144. err:
  145. snd_soc_unregister_dai(&pdev->dev);
  146. return ret;
  147. }
  148. static int s3c2412_iis_dev_remove(struct platform_device *pdev)
  149. {
  150. asoc_dma_platform_unregister(&pdev->dev);
  151. snd_soc_unregister_dai(&pdev->dev);
  152. return 0;
  153. }
  154. static struct platform_driver s3c2412_iis_driver = {
  155. .probe = s3c2412_iis_dev_probe,
  156. .remove = s3c2412_iis_dev_remove,
  157. .driver = {
  158. .name = "s3c2412-iis",
  159. .owner = THIS_MODULE,
  160. },
  161. };
  162. module_platform_driver(s3c2412_iis_driver);
  163. /* Module information */
  164. MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
  165. MODULE_DESCRIPTION("S3C2412 I2S SoC Interface");
  166. MODULE_LICENSE("GPL");
  167. MODULE_ALIAS("platform:s3c2412-iis");