s3c2412-i2s.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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/gpio-samsung.h>
  26. #include <plat/gpio-cfg.h>
  27. #include "dma.h"
  28. #include "regs-i2s-v2.h"
  29. #include "s3c2412-i2s.h"
  30. #include <linux/platform_data/asoc-s3c.h>
  31. static struct snd_dmaengine_dai_dma_data s3c2412_i2s_pcm_stereo_out = {
  32. .chan_name = "tx",
  33. .addr_width = 4,
  34. };
  35. static struct snd_dmaengine_dai_dma_data s3c2412_i2s_pcm_stereo_in = {
  36. .chan_name = "rx",
  37. .addr_width = 4,
  38. };
  39. static struct s3c_i2sv2_info s3c2412_i2s;
  40. static int s3c2412_i2s_probe(struct snd_soc_dai *dai)
  41. {
  42. int ret;
  43. pr_debug("Entered %s\n", __func__);
  44. snd_soc_dai_init_dma_data(dai, &s3c2412_i2s_pcm_stereo_out,
  45. &s3c2412_i2s_pcm_stereo_in);
  46. ret = s3c_i2sv2_probe(dai, &s3c2412_i2s, S3C2410_PA_IIS);
  47. if (ret)
  48. return ret;
  49. s3c2412_i2s.dma_capture = &s3c2412_i2s_pcm_stereo_in;
  50. s3c2412_i2s.dma_playback = &s3c2412_i2s_pcm_stereo_out;
  51. s3c2412_i2s.iis_cclk = devm_clk_get(dai->dev, "i2sclk");
  52. if (IS_ERR(s3c2412_i2s.iis_cclk)) {
  53. pr_err("failed to get i2sclk clock\n");
  54. return PTR_ERR(s3c2412_i2s.iis_cclk);
  55. }
  56. /* Set MPLL as the source for IIS CLK */
  57. clk_set_parent(s3c2412_i2s.iis_cclk, clk_get(NULL, "mpll"));
  58. clk_prepare_enable(s3c2412_i2s.iis_cclk);
  59. s3c2412_i2s.iis_cclk = s3c2412_i2s.iis_pclk;
  60. /* Configure the I2S pins (GPE0...GPE4) in correct mode */
  61. s3c_gpio_cfgall_range(S3C2410_GPE(0), 5, S3C_GPIO_SFN(2),
  62. S3C_GPIO_PULL_NONE);
  63. return 0;
  64. }
  65. static int s3c2412_i2s_remove(struct snd_soc_dai *dai)
  66. {
  67. clk_disable_unprepare(s3c2412_i2s.iis_cclk);
  68. return 0;
  69. }
  70. static int s3c2412_i2s_hw_params(struct snd_pcm_substream *substream,
  71. struct snd_pcm_hw_params *params,
  72. struct snd_soc_dai *cpu_dai)
  73. {
  74. struct s3c_i2sv2_info *i2s = snd_soc_dai_get_drvdata(cpu_dai);
  75. u32 iismod;
  76. pr_debug("Entered %s\n", __func__);
  77. iismod = readl(i2s->regs + S3C2412_IISMOD);
  78. pr_debug("%s: r: IISMOD: %x\n", __func__, iismod);
  79. switch (params_width(params)) {
  80. case 8:
  81. iismod |= S3C2412_IISMOD_8BIT;
  82. break;
  83. case 16:
  84. iismod &= ~S3C2412_IISMOD_8BIT;
  85. break;
  86. }
  87. writel(iismod, i2s->regs + S3C2412_IISMOD);
  88. pr_debug("%s: w: IISMOD: %x\n", __func__, iismod);
  89. return 0;
  90. }
  91. #define S3C2412_I2S_RATES \
  92. (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
  93. SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
  94. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
  95. static const struct snd_soc_dai_ops s3c2412_i2s_dai_ops = {
  96. .hw_params = s3c2412_i2s_hw_params,
  97. };
  98. static struct snd_soc_dai_driver s3c2412_i2s_dai = {
  99. .probe = s3c2412_i2s_probe,
  100. .remove = s3c2412_i2s_remove,
  101. .playback = {
  102. .channels_min = 2,
  103. .channels_max = 2,
  104. .rates = S3C2412_I2S_RATES,
  105. .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,
  106. },
  107. .capture = {
  108. .channels_min = 2,
  109. .channels_max = 2,
  110. .rates = S3C2412_I2S_RATES,
  111. .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,
  112. },
  113. .ops = &s3c2412_i2s_dai_ops,
  114. };
  115. static const struct snd_soc_component_driver s3c2412_i2s_component = {
  116. .name = "s3c2412-i2s",
  117. };
  118. static int s3c2412_iis_dev_probe(struct platform_device *pdev)
  119. {
  120. int ret = 0;
  121. struct resource *res;
  122. struct s3c_audio_pdata *pdata = dev_get_platdata(&pdev->dev);
  123. if (!pdata) {
  124. dev_err(&pdev->dev, "missing platform data");
  125. return -ENXIO;
  126. }
  127. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  128. s3c2412_i2s.regs = devm_ioremap_resource(&pdev->dev, res);
  129. if (IS_ERR(s3c2412_i2s.regs))
  130. return PTR_ERR(s3c2412_i2s.regs);
  131. s3c2412_i2s_pcm_stereo_out.addr = res->start + S3C2412_IISTXD;
  132. s3c2412_i2s_pcm_stereo_out.filter_data = pdata->dma_playback;
  133. s3c2412_i2s_pcm_stereo_in.addr = res->start + S3C2412_IISRXD;
  134. s3c2412_i2s_pcm_stereo_in.filter_data = pdata->dma_capture;
  135. ret = samsung_asoc_dma_platform_register(&pdev->dev,
  136. pdata->dma_filter,
  137. NULL, NULL);
  138. if (ret) {
  139. pr_err("failed to register the DMA: %d\n", ret);
  140. return ret;
  141. }
  142. ret = s3c_i2sv2_register_component(&pdev->dev, -1,
  143. &s3c2412_i2s_component,
  144. &s3c2412_i2s_dai);
  145. if (ret)
  146. pr_err("failed to register the dai\n");
  147. return ret;
  148. }
  149. static struct platform_driver s3c2412_iis_driver = {
  150. .probe = s3c2412_iis_dev_probe,
  151. .driver = {
  152. .name = "s3c2412-iis",
  153. },
  154. };
  155. module_platform_driver(s3c2412_iis_driver);
  156. /* Module information */
  157. MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
  158. MODULE_DESCRIPTION("S3C2412 I2S SoC Interface");
  159. MODULE_LICENSE("GPL");
  160. MODULE_ALIAS("platform:s3c2412-iis");