s3c2412-i2s.c 5.2 KB

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